pub struct Vec<T, const N: usize> { /* private fields */ }Expand description
This is a vector that can store up to N elements inline and will allocate on the heap if more are needed.
Implementations§
Source§impl<T: Clone + Copy, const N: usize> Vec<T, N>
impl<T: Clone + Copy, const N: usize> Vec<T, N>
Sourcepub fn reserve(&mut self, additional: usize) -> Result<(), KernelError>
pub fn reserve(&mut self, additional: usize) -> Result<(), KernelError>
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<(), KernelError>
pub fn reserve_total_capacity( &mut self, total_capacity: usize, ) -> Result<(), KernelError>
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, KernelError>
pub fn new_init(length: usize, value: T) -> Result<Self, KernelError>
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<(), KernelError>
pub fn push(&mut self, value: T) -> Result<(), KernelError>
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.
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.