Struct mesh_protobuf::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>
impl<'a, T> InplaceOption<'a, T>
sourcepub fn uninit(val: &'a mut MaybeUninit<T>) -> Self
pub fn uninit(val: &'a mut MaybeUninit<T>) -> Self
Creates an option in the uninitialized state.
sourcepub unsafe fn new_init_unchecked(val: &'a mut MaybeUninit<T>) -> Self
pub unsafe fn new_init_unchecked(val: &'a mut MaybeUninit<T>) -> Self
Creates an option in the initialized state.
§Safety
The caller must guarantee that the value referenced by val
is
initialized.
sourcepub unsafe fn set_init_unchecked(&mut self) -> &mut T
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.
sourcepub fn take(&mut self) -> Option<T>
pub fn take(&mut self) -> Option<T>
Takes the value, returning Some(_)
if the value is initialized and
None
otherwise.
sourcepub fn as_mut(&mut self) -> Option<&mut T>
pub fn as_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the data if it’s initialized.
sourcepub fn forget(&mut self) -> bool
pub fn forget(&mut self) -> bool
Resets the data to the uninitialized state without dropping any initialized value.
sourcepub fn set(&mut self, v: T) -> &mut T
pub fn set(&mut self, v: T) -> &mut T
Initializes the value to v
, dropping any existing value first.
sourcepub fn get_or_insert(&mut self, v: T) -> &mut T
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.
sourcepub fn get_or_insert_with(&mut self, f: impl FnOnce() -> T) -> &mut T
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.
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns a const pointer to the underlying value (initialized or not).
sourcepub fn as_mut_ptr(&mut self) -> *mut T
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>>
impl<'a, T> InplaceOption<'a, Box<T>>
sourcepub fn update_box<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(&mut InplaceOption<'_, T>) -> R,
pub fn update_box<F, R>(&mut self, f: F) -> Rwhere
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: Clone> InplaceOption<'a, Arc<T>>
impl<'a, T: Clone> InplaceOption<'a, Arc<T>>
sourcepub fn update_arc<F, R>(&mut self, f: F) -> Rwhere
F: FnOnce(&mut InplaceOption<'_, T>) -> R,
pub fn update_arc<F, R>(&mut self, f: F) -> Rwhere
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.