Skip to main content

UncheckedCell

Struct UncheckedCell 

Source
pub struct UncheckedCell<T> {
    value: UnsafeCell<MaybeUninit<T>>,
}
Expand description

A datatype with interior mutability, which can be uninitialized via [MaybeUninit] When the cargo feature debug-checks is enabled, this type also checks for double initialization and uninitialized access.

Fields§

§value: UnsafeCell<MaybeUninit<T>>

Implementations§

Source§

impl<T> UncheckedCell<T>

Source

pub const fn new() -> Self

Constructor; creates a new UncheckedCell

Source

pub unsafe fn init(&self, value: T)

Initialize the inner value

§Safety

The caller must guarantee the following:

  • That this method has never been called before and will never be called again
  • That at the time of calling this method, no references or pointers to this data exist
  • While this method is being called, no other CPU is working with the given data
Source

pub unsafe fn get(&self) -> &T

Get a reference to the inner value

§Safety

The caller must guarantee the following:

  • That this value’s init method has already been called before
  • That at this method’s entire execution time, no mutable references or pointers to this data exist or will exist

Trait Implementations§

Source§

impl<T: Send + Sync> Sync for UncheckedCell<T>

Safety: this type can be shared across CPUs as the callers have the responsibility to ensure proper data safety because of the unsafe contracts on init and get

Auto Trait Implementations§

§

impl<T> !Freeze for UncheckedCell<T>

§

impl<T> !RefUnwindSafe for UncheckedCell<T>

§

impl<T> Send for UncheckedCell<T>
where UnsafeCell<MaybeUninit<T>>: Send,

§

impl<T> Unpin for UncheckedCell<T>
where UnsafeCell<MaybeUninit<T>>: Unpin,

§

impl<T> UnsafeUnpin for UncheckedCell<T>
where UnsafeCell<MaybeUninit<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for UncheckedCell<T>
where UnsafeCell<MaybeUninit<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.