Struct Maybe

Source
pub struct Maybe<T> { /* private fields */ }
Expand description

Equivalent to an UnsafeCell<MaybeUninit<T>>, this cell may hold uninitialized data.

Implementations§

Source§

impl<T> Maybe<T>

Source

pub const fn empty() -> Self

Create a new, empty Maybe<T>.

Source

pub const fn new(data: T) -> Self

Create a new, populated Maybe<T>.

Source

pub unsafe fn as_ptr(&self) -> *const T

Access the contained value as a constant pointer.

Source

pub unsafe fn as_mut_ptr(&mut self) -> *mut T

Access the contained value as a mutable pointer.

Source

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

Obtain a reference to the contained value. This method is unsafe because the value may not have been initialized.

Source

pub unsafe fn as_mut(&mut self) -> &mut T

Obtain a mutable reference to the contained value.

Source

pub fn set_loaded(&self, loaded: bool)

Override the loaded flag of the cell. This method is a no-op when using the unchecked implementation. It may be used when a value is inserted manually, for example by assigning to the dereferenced pointer.

Source

pub unsafe fn clear(&self)

Drop the contained value in place.

Source

pub unsafe fn load(&self) -> T

Load the contained value.

Source

pub unsafe fn replace(&self, value: T) -> T

Store a new value in an occupied cell.

Source

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

Store a new value in an empty cell.

Trait Implementations§

Source§

impl<T: Debug> Debug for Maybe<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for Maybe<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> From<T> for Maybe<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> !Freeze for Maybe<T>

§

impl<T> !RefUnwindSafe for Maybe<T>

§

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

§

impl<T> !Sync for Maybe<T>

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.