-
Notifications
You must be signed in to change notification settings - Fork 17
feat: implement InPlaceWrite<T> for &'static mut MaybeUninit<T>
#91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7224def to
ce11e2b
Compare
InPlaceWrite<T> for &'a mut MaybeUninit<T>InPlaceWrite<T> for &'static mut MaybeUninit<T>
ce11e2b to
8f11de9
Compare
|
Oh yeah that works, thanks for the contribution by the way! Can you add a commit message containing a description of your change? Also the title of the commit contains |
8f11de9 to
8ffcd06
Compare
|
I updated the commit message, is it fine? For the safety comment, I borrowed it from That CI failure, it seems flaky. Like, no code had changed and tests pass on my machine. |
src/lib.rs
Outdated
| // SAFETY: | ||
| // - The above call initialized the memory. | ||
| // - The 'static borrow guarantees the data will not be moved/invalidated | ||
| // until it gets dropped (which is never). | ||
| Ok(unsafe { Pin::new_unchecked(&mut *slot) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be much better to use Pin::static_mut and MaybeUninit::assume_init_mut to obtain the pinned reference. Then you only need the justification for the initialized memory.
(same for write_init I guess? (without Pin of course))
Yeah the ui tests also failed this morning on the main branch, the nightly output has changed, I'll wait a few days to see if that's intentional. Can you also add a bullet point about this change into the changelog? The commit message needs a bit more motivation, would be great if you could mention that you want to use it with |
971d43b to
e809736
Compare
This feature allows users to use `&'static mut MaybeUninit<T>` as a place to initialize the value. It mirrors an existing implemetation for `Box<MaybeUninit>`, but enables users to use external allocation mechanisms such as `static_cell`. Signed-off-by: Oleksandr Babak <[email protected]>
e809736 to
883000b
Compare
InPlaceWrite<T> for &'static mut MaybeUninit<T>InPlaceWrite<T> for &'static mut MaybeUninit<T>
Simple PR to implemente
InPlaceWritefor a mutable reference. In my code the use case is to useStaticCell::uninit()to get&'static mut MaybeUninit<T>.