Avoid moves in debug builds with MaybeUninit
(once we are ready)
#97
Labels
feature request
A new feature is requested
MaybeUninit
(once we are ready)
#97
This is based on a reddit comment
The proposal is to implement a builder that uses
MaybeUninit<Fields>
under the hood and doesptr::write/read
to access the underlying fields. It does so safely because the builder has the info about which fields are initialized using the type state.I'm writing up this issue for the future when bon is more stable and feature complete, at which point the cost of maintaining
unsafe
code isn't that high.Motivation
This will allow for better-optimized debug builds. The current approach of using the safe code doesn't allow for that because it moves data around and relies on compiler optimizations. With the
MaybeUnint
version we don't move anything and just mutate an existing memory.Note on the important caveat that there must be a generic
Drop
implementation that makes sure all fields that were initialized are dropped in case when only part of the fields were initialized (e.g. there was a panic or an error in the middle).The text was updated successfully, but these errors were encountered: