4 ms·
Easier said than done. You can already have: unsafe fn new_in_place(out: &mut MaybeUninit<MyType>) But you require unsafe code both to implement it (to p
by wmanley 4y ago
Easier said than done. You can already have:
unsafe fn new_in_place(out: &mut MaybeUninit<MyType>)
But you require unsafe code both to implement it (to project MaybeUninit) and to call it.
For it to be safe to call the type system would have to encode the invariant that &out is initialised after the call. It becomes even more complicated if the operation can fail.
- Ericson2314 4y agoYes, you do. This is the cost of doing business. I'm OK with it. If one doesn't want to deal with imperative programming in all its glory, go write Haskell or something. (I do that too.)
- Ericson2314 4y agoAs a stepping stone. we could worry just about the panic=abort case, where this is all easier. For panicking, I think we would want to switch to a model where borrower not borowee runs destructor for &mut; that way we can support "moving out of &mut temporarily" too.