Skip to content

Conversation

@Ddystopia
Copy link

Simple PR to implemente InPlaceWrite for a mutable reference. In my code the use case is to use StaticCell::uninit() to get &'static mut MaybeUninit<T>.

@Ddystopia Ddystopia changed the title feat: imple InPlaceWrite<T> for &'a mut MaybeUninit<T> feat: imple InPlaceWrite<T> for &'static mut MaybeUninit<T> Oct 31, 2025
@Ddystopia Ddystopia requested a review from BennoLossin October 31, 2025 16:26
@BennoLossin
Copy link
Member

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 feat (& a typo), I don't use that convention. Have you read the contribution guidelines they contain some useful information and links?

@Ddystopia
Copy link
Author

I updated the commit message, is it fine? For the safety comment, I borrowed it from Pin::static_mut documentation.

That CI failure, it seems flaky. Like, no code had changed and tests pass on my machine.

src/lib.rs Outdated
Comment on lines 1466 to 1470
// 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) })
Copy link
Member

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))

@BennoLossin
Copy link
Member

I updated the commit message, is it fine? For the safety comment, I borrowed it from Pin::static_mut documentation.

That CI failure, it seems flaky. Like, no code had changed and tests pass on my machine.

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 static_cell. Also I wouldn't say that this "avoids allocations", but rather enables users to use external allocation mechanisms (like static_cell).

@Ddystopia Ddystopia force-pushed the impl_for_mut_ref branch 2 times, most recently from 971d43b to e809736 Compare November 2, 2025 16:11
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]>
@Ddystopia Ddystopia requested a review from BennoLossin November 2, 2025 17:20
@Ddystopia Ddystopia changed the title feat: imple InPlaceWrite<T> for &'static mut MaybeUninit<T> feat: implement InPlaceWrite<T> for &'static mut MaybeUninit<T> Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants