SyncNoinit

Struct SyncNoinit 

Source
pub struct SyncNoinit<T>(pub UnsafeCell<MaybeUninit<T>>);
Expand description

A Sync wrapper around UnsafeCell<MaybeUninit<T>> for use with #[link_section = ".uninit"] statics.

Rust 2024 made &mut static_mut a hard error (static_mut_refs lint). UnsafeCell is the correct escape hatch: it opts into interior mutability, so a raw pointer obtained via UnsafeCell::get() is not a reference to a mutable static. The unsafe impl Sync is sound on a single-core target where no thread can race on the cell.

Tuple Fields§

§0: UnsafeCell<MaybeUninit<T>>

Implementations§

Source§

impl<T> SyncNoinit<T>

Source

pub const fn uninit() -> Self

Source

pub unsafe fn as_bytes_mut(&self) -> &'static mut [u8]

Return a &'static mut [u8] slice over the inner value.

§Safety

The caller must ensure no other live reference to this cell exists.

Trait Implementations§

Source§

impl<T> Sync for SyncNoinit<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SyncNoinit<T>

§

impl<T> !RefUnwindSafe for SyncNoinit<T>

§

impl<T> Send for SyncNoinit<T>
where T: Send,

§

impl<T> Unpin for SyncNoinit<T>
where T: Unpin,

§

impl<T> UnwindSafe for SyncNoinit<T>
where T: UnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.