Struct mesh::payload::inplace::InplaceOption

source ·
pub struct InplaceOption<'a, T> { /* private fields */ }
Expand description

A type with methods like Option but that operates on a mutable reference to possibly-initialized data.

This is used to initialize data in place without copying to/from Option types.

Implementations§

source§

impl<'a, T> InplaceOption<'a, T>

source

pub fn uninit(val: &'a mut MaybeUninit<T>) -> InplaceOption<'a, T>

Creates an option in the uninitialized state.

source

pub unsafe fn new_init_unchecked( val: &'a mut MaybeUninit<T>, ) -> InplaceOption<'a, T>

Creates an option in the initialized state.

§Safety

The caller must guarantee that the value referenced by val is initialized.

source

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

Sets the value to the initialized state.

§Safety

The caller must guarantee that the underlying data has been fully initialized.

source

pub fn take(&mut self) -> Option<T>

Takes the value, returning Some(_) if the value is initialized and None otherwise.

source

pub fn as_ref(&self) -> Option<&T>

Returns a reference to the data if it’s initialized.

source

pub fn as_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the data if it’s initialized.

source

pub fn clear(&mut self)

Clears the data to the uninitialized state.

source

pub fn forget(&mut self) -> bool

Resets the data to the uninitialized state without dropping any initialized value.

source

pub fn set(&mut self, v: T) -> &mut T

Initializes the value to v, dropping any existing value first.

source

pub fn get_or_insert(&mut self, v: T) -> &mut T

Gets a mutable reference to the value, setting it to v first if it’s not initialized.

source

pub fn get_or_insert_with(&mut self, f: impl FnOnce() -> T) -> &mut T

Gets a mutable reference to the value, setting it to f() first if it’s not initialized.

source

pub fn is_some(&self) -> bool

Returns whether the value is initialized.

source

pub fn is_none(&self) -> bool

Returns whether the value is uninitialized.

source

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

Returns a const pointer to the underlying value (initialized or not).

source

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

Returns a mut pointer to the underlying value (initialized or not).

source§

impl<'a, T> InplaceOption<'a, Box<T>>

source

pub fn update_box<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut InplaceOption<'_, T>) -> R,

Updates a boxed value in place.

N.B. This will allocate space for a value if one is not already present, which is wasteful if f does not actually initialize the value.

source§

impl<'a, T> InplaceOption<'a, Arc<T>>
where T: Clone,

source

pub fn update_arc<F, R>(&mut self, f: F) -> R
where F: FnOnce(&mut InplaceOption<'_, T>) -> R,

Updates a reference counted value in place.

N.B. This will allocate space for a value if one is not already present, which is wasteful if f does not actually initialize the value.

Trait Implementations§

source§

impl<T> Drop for InplaceOption<'_, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for InplaceOption<'a, T>

§

impl<'a, T> RefUnwindSafe for InplaceOption<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for InplaceOption<'a, T>
where T: Send,

§

impl<'a, T> Sync for InplaceOption<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for InplaceOption<'a, T>

§

impl<'a, T> !UnwindSafe for InplaceOption<'a, T>

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<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T, U> Upcast<U> for T
where U: Downcast<T>,