pub struct MaybeData<Data>where
Data: TrivialType,{ /* private fields */ }
Expand description
Wrapper type for Data
that may or may not be filled with contents.
This is somewhat similar to VariableBytes
, but instead
of variable size data structure allows to either have it or not have the contents or not have
it, which is a simpler and more convenient API that is also sufficient in many cases.
Implementations§
Source§impl<Data> MaybeData<Data>where
Data: TrivialType,
impl<Data> MaybeData<Data>where
Data: TrivialType,
Sourcepub fn from_buffer(data: Option<&Data>) -> impl Deref<Target = Self> + '_
pub fn from_buffer(data: Option<&Data>) -> impl Deref<Target = Self> + '_
Create a new shared instance from provided data reference.
Sourcepub fn from_buffer_mut<'a>(
buffer: &'a mut Data,
size: &'a mut u32,
) -> impl DerefMut<Target = Self> + 'a
pub fn from_buffer_mut<'a>( buffer: &'a mut Data, size: &'a mut u32, ) -> impl DerefMut<Target = Self> + 'a
Create a new exclusive instance from provided data reference.
size
can be either 0
or Data::SIZE
, indicating that value is missing or present
accordingly.
§Panics
Panics if size != 0 && size != Data::SIZE
Sourcepub fn from_uninit<'a>(
uninit: &'a mut MaybeUninit<Data>,
size: &'a mut u32,
) -> impl Deref<Target = Self> + 'a
pub fn from_uninit<'a>( uninit: &'a mut MaybeUninit<Data>, size: &'a mut u32, ) -> impl Deref<Target = Self> + 'a
Create a new shared instance from provided memory buffer.
size
must be 0
.
§Panics
Panics if size != 0
Sourcepub fn get(&self) -> Option<&Data>
pub fn get(&self) -> Option<&Data>
Try to get access to initialized Data
, returns None
if not initialized
Sourcepub fn get_mut(&mut self) -> Option<&mut Data>
pub fn get_mut(&mut self) -> Option<&mut Data>
Try to get exclusive access to initialized Data
, returns None
if not initialized
Sourcepub fn replace(&mut self, data: Data) -> &mut Data
pub fn replace(&mut self, data: Data) -> &mut Data
Initialize by inserting Data
by value or replace existing value and return reference to it
Sourcepub fn get_mut_or_init_with<'a, Init>(&'a mut self, init: Init) -> &'a mut Data
pub fn get_mut_or_init_with<'a, Init>(&'a mut self, init: Init) -> &'a mut Data
Get exclusive access to initialized Data
, running provided initialization function if
necessary
Sourcepub unsafe fn assume_init(&mut self) -> &mut Data
pub unsafe fn assume_init(&mut self) -> &mut Data
Trait Implementations§
Source§impl<Data> IoType for MaybeData<Data>where
Data: TrivialType,
impl<Data> IoType for MaybeData<Data>where
Data: TrivialType,
Source§const METADATA: &[u8] = Data::METADATA
const METADATA: &[u8] = Data::METADATA
IoTypeMetadataKind
for encoding detailsSource§type PointerType = Data
type PointerType = Data
IoType
represents