Trait data_model::flexible_array::FlexibleArray
source · pub trait FlexibleArray<S> {
// Required methods
fn set_len(&mut self, len: usize);
fn get_len(&self) -> usize;
unsafe fn get_slice(&self, len: usize) -> &[S];
unsafe fn get_mut_slice(&mut self, len: usize) -> &mut [S];
}
Expand description
The following code provides generic helpers for creating and accessing flexible array structs. A complete definition of flexible array structs is found in the ISO 9899 specification http://www.iso-9899.info/n1570.html. A flexible array struct is of the form:
#[repr(C)]
struct T {
some_data: u32,
nents: u32,
entries: __IncompleteArrayField<S>,
}
where:
T
is the flexible array struct typeS
is the flexible array typenents
is the flexible array lengthentries
is the flexible array member
These structures are used by the kernel API. A collection of methods that are required by the FlexibleArrayWrapper type.
When implemented for T
, this trait allows the caller to set number of S
entries and
retrieve a slice of S
entries. Trait methods must only be called by the FlexibleArrayWrapper
type. Don’t implement this trait directly, use the flexible_array! macro to avoid duplication.
Required Methods§
sourcefn set_len(&mut self, len: usize)
fn set_len(&mut self, len: usize)
Implementations must set flexible array length in the flexible array struct to the value
specified by len
. Appropriate conversions (i.e, usize to u32) are allowed so long as
they don’t overflow or underflow.
sourcefn get_len(&self) -> usize
fn get_len(&self) -> usize
Implementations must return the length of the flexible array member. Appropriate conversions (i.e, usize to u32) are allowed so long as they don’t overflow or underflow.
sourceunsafe fn get_slice(&self, len: usize) -> &[S]
unsafe fn get_slice(&self, len: usize) -> &[S]
Implementations must return a slice of flexible array member of length len
.
§Safety
Do not use this function directly, as the FlexibleArrayWrapper will guarantee safety.
sourceunsafe fn get_mut_slice(&mut self, len: usize) -> &mut [S]
unsafe fn get_mut_slice(&mut self, len: usize) -> &mut [S]
Implementations must return a mutable slice of flexible array member of length len
.
§Safety
Do not use this function directly, as the FlexibleArrayWrapper will guarantee safety.