Struct data_model::flexible_array::FlexibleArrayWrapper
source · pub struct FlexibleArrayWrapper<T, S> {
entries: Vec<T>,
phantom: PhantomData<S>,
allocated_len: usize,
}
Fields§
§entries: Vec<T>
§phantom: PhantomData<S>
§allocated_len: usize
Implementations§
source§impl<T, S> FlexibleArrayWrapper<T, S>where
T: FlexibleArray<S> + Default,
impl<T, S> FlexibleArrayWrapper<T, S>where
T: FlexibleArray<S> + Default,
Convenience wrapper for flexible array structs.
The FlexibleArray trait must be implemented for the flexible array struct before using this wrapper.
sourcepub fn new(array_len: usize) -> FlexibleArrayWrapper<T, S>
pub fn new(array_len: usize) -> FlexibleArrayWrapper<T, S>
Creates a new FlexibleArrayWrapper for the given flexible array struct type and flexible
array type. The flexible array length is set to array_len
. vec_with_array_field is used
to make sure the resultant wrapper is appropriately sized.
sourcefn get_valid_len(&self) -> usize
fn get_valid_len(&self) -> usize
Mapping the unsized array to a slice is unsafe because the length isn’t known. Using the length we originally allocated with eliminates the possibility of overflow.
sourcepub fn entries_slice(&self) -> &[S]
pub fn entries_slice(&self) -> &[S]
Returns a slice of the flexible array member, for inspecting. To modify, use mut_entries_slice instead.
sourcepub fn mut_entries_slice(&mut self) -> &mut [S]
pub fn mut_entries_slice(&mut self) -> &mut [S]
Returns a mutable slice of the flexible array member, for modifying.
sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Get a pointer so it can be passed to the kernel. Callers must not access the flexible array member. Using this pointer is unsafe.
sourcepub fn as_mut_ptr(&mut self) -> *mut T
pub fn as_mut_ptr(&mut self) -> *mut T
Get a mutable pointer so it can be passed to the kernel. Callers must not access the flexible array member. Using this pointer is unsafe.