vmm_sys_util::fam

Struct FamStructWrapper

Source
pub struct FamStructWrapper<T: Default + FamStruct> { /* private fields */ }
Expand description

A wrapper for FamStruct.

It helps in treating a FamStruct similarly to an actual Vec.

Implementations§

Source§

impl<T: Default + FamStruct> FamStructWrapper<T>

Source

pub fn new(num_elements: usize) -> Result<FamStructWrapper<T>, Error>

Create a new FamStructWrapper with num_elements elements.

The elements will be zero-initialized. The type of the elements will be FamStruct::Entry.

§Arguments
  • num_elements - The number of elements in the FamStructWrapper.
§Errors

When num_elements is greater than the max possible len, it returns Error::SizeLimitExceeded.

Source

pub fn from_entries(entries: &[T::Entry]) -> Result<FamStructWrapper<T>, Error>

Create a new FamStructWrapper from a slice of elements.

§Arguments
§Errors

When the size of entries is greater than the max possible len, it returns Error::SizeLimitExceeded.

Source

pub unsafe fn from_raw(content: Vec<T>) -> Self

Create a new FamStructWrapper from the raw content represented as Vec<T>.

Sometimes we already have the raw content of an FAM struct represented as Vec<T>, and want to use the FamStructWrapper as accessors.

§Arguments
  • content - The raw content represented as Vec[T].
§Safety

This function is unsafe because the caller needs to ensure that the raw content is correctly layed out.

Source

pub fn into_raw(self) -> Vec<T>

Consume the FamStructWrapper and return the raw content as Vec<T>.

Source

pub fn as_fam_struct_ref(&self) -> &T

Get a reference to the actual FamStruct instance.

Source

pub fn as_mut_fam_struct(&mut self) -> &mut T

Get a mut reference to the actual FamStruct instance.

Source

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

Get a pointer to the FamStruct instance.

The caller must ensure that the fam_struct outlives the pointer this function returns, or else it will end up pointing to garbage.

Modifying the container referenced by this pointer may cause its buffer to be reallocated, which would also make any pointers to it invalid.

Source

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

Get a mutable pointer to the FamStruct instance.

The caller must ensure that the fam_struct outlives the pointer this function returns, or else it will end up pointing to garbage.

Modifying the container referenced by this pointer may cause its buffer to be reallocated, which would also make any pointers to it invalid.

Source

pub fn as_slice(&self) -> &[T::Entry]

Get the elements slice.

Source

pub fn as_mut_slice(&mut self) -> &mut [T::Entry]

Get the mutable elements slice.

Source

pub fn push(&mut self, entry: T::Entry) -> Result<(), Error>

Append an element.

§Arguments
  • entry - The element that will be appended to the end of the collection.
§Errors

When len is already equal to max possible len it returns Error::SizeLimitExceeded.

Source

pub fn retain<P>(&mut self, f: P)
where P: FnMut(&T::Entry) -> bool,

Retain only the elements specified by the predicate.

§Arguments
  • f - The function used to evaluate whether an entry will be kept or not. When f returns true the entry is kept.

Trait Implementations§

Source§

impl<T: Default + FamStruct> Clone for FamStructWrapper<T>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Default + FamStruct> Debug for FamStructWrapper<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default + FamStruct> From<Vec<T>> for FamStructWrapper<T>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Default + FamStruct + PartialEq> PartialEq for FamStructWrapper<T>

Source§

fn eq(&self, other: &FamStructWrapper<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> Freeze for FamStructWrapper<T>

§

impl<T> RefUnwindSafe for FamStructWrapper<T>
where T: RefUnwindSafe,

§

impl<T> Send for FamStructWrapper<T>
where T: Send,

§

impl<T> Sync for FamStructWrapper<T>
where T: Sync,

§

impl<T> Unpin for FamStructWrapper<T>
where T: Unpin,

§

impl<T> UnwindSafe for FamStructWrapper<T>
where T: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.