pub struct Vec<T, const N: usize> {
len: usize,
data: [MaybeUninit<T>; N],
extra: Box<[MaybeUninit<T>]>,
}Expand description
This is a vector that can store up to N elements inline and will allocate on the heap if more are needed.
Fields§
§len: usize§data: [MaybeUninit<T>; N]§extra: Box<[MaybeUninit<T>]>Implementations§
Source§impl<T: Clone + Copy, const N: usize> Vec<T, N>
impl<T: Clone + Copy, const N: usize> Vec<T, N>
pub const fn from_array(arr: [T; N]) -> Self
Sourcepub fn reserve(&mut self, additional: usize) -> Result<(), Error>
pub fn reserve(&mut self, additional: usize) -> Result<(), Error>
Reserve additional space in the Vec.
additional - The additional space to reserve.
Returns Ok(()) if the space was reserved, otherwise Err(KernelError::OutOfMemory).
Sourcepub fn reserve_total_capacity(
&mut self,
total_capacity: usize,
) -> Result<(), Error>
pub fn reserve_total_capacity( &mut self, total_capacity: usize, ) -> Result<(), Error>
Reserve a fixed amount of space in the Vec. Does nothing if enough space is present already.
total_capacity - The total space to be reserved.
Returns Ok(()) if the space was reserved, otherwise Err(KernelError::OutOfMemory).
Sourcepub fn new_init(length: usize, value: T) -> Result<Self, Error>
pub fn new_init(length: usize, value: T) -> Result<Self, Error>
Create a new Vec with the given length and value.
length - The length of the Vec.
value - The value to initialize the elements in the Vec with.
Returns the new Vec or Err(KernelError::OutOfMemory) if the allocation failed.
Sourcepub fn push(&mut self, value: T) -> Result<(), Error>
pub fn push(&mut self, value: T) -> Result<(), Error>
Push a value onto the Vec.
value - The value to push.
Returns Ok(()) if the value was pushed, otherwise Err(KernelError::OutOfMemory).
Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pop a value from the Vec.
Returns the value if it was popped, otherwise None.
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Remove the value at the given index.
index - The index to remove the value from.
Returns the value if it was removed, otherwise None.
Sourcepub fn at(&self, index: usize) -> Option<&T>
pub fn at(&self, index: usize) -> Option<&T>
Get the value at the given index.
index - The index to get the value from.
Returns Some(&T) if the index is in-bounds, otherwise None.
Sourcepub fn at_mut(&mut self, index: usize) -> Option<&mut T>
pub fn at_mut(&mut self, index: usize) -> Option<&mut T>
Get a mutable reference to the value at the given index.
index - The index to get the value from.
Returns Some(&mut T) if the index is in-bounds, otherwise None.
fn at_mut_unchecked(&mut self, index: usize) -> *mut T
Sourcepub fn at2_mut(
&mut self,
index1: usize,
index2: usize,
) -> (Option<&mut T>, Option<&mut T>)
pub fn at2_mut( &mut self, index1: usize, index2: usize, ) -> (Option<&mut T>, Option<&mut T>)
Get disjoint mutable references to the values at the given indices.
index1 - The first index.
index2 - The second index.
Returns Some(&mut T, &mut T) if the indices are in-bounds and disjoint, otherwise None.
Sourcepub fn at3_mut(
&mut self,
index1: usize,
index2: usize,
index3: usize,
) -> (Option<&mut T>, Option<&mut T>, Option<&mut T>)
pub fn at3_mut( &mut self, index1: usize, index2: usize, index3: usize, ) -> (Option<&mut T>, Option<&mut T>, Option<&mut T>)
Get disjoint mutable references to the values at the given indices.
index1 - The first index.
index2 - The second index.
index3 - The third index.
Returns Some(&mut T, &mut T, &mut T) if the indices are in-bounds and disjoint, otherwise None.
Sourcepub fn swap(&mut self, a: usize, b: usize)
pub fn swap(&mut self, a: usize, b: usize)
Swap the values at the given indices.
a - The first index.
b - The second index.