Struct Vec

Source
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>

Source

pub const fn new() -> Self

Create a new Vec.

Returns a new Vec.

Source

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).

Source

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).

Source

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.

Source

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).

Source

pub fn pop(&mut self) -> Option<T>

Pop a value from the Vec.

Returns the value if it was popped, otherwise None.

Source

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.

Source

pub fn len(&self) -> usize

Get the length of the Vec.

Returns the length of the Vec.

Source

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.

Source

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.

Source

pub fn swap(&mut self, a: usize, b: usize)

Swap the values at the given indices.

a - The first index. b - The second index.

Source

pub fn is_empty(&self) -> bool

Check if the Vec is empty.

Returns true if the Vec is empty, otherwise false.

Source

pub fn capacity(&self) -> usize

Get total amount of space in Vec (in- and out-of-line)

Returns total amount of reserved space in the vec

Trait Implementations§

Source§

impl<T, const N: usize> Drop for Vec<T, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for Vec<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for Vec<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> !Send for Vec<T, N>

§

impl<T, const N: usize> !Sync for Vec<T, N>

§

impl<T, const N: usize> Unpin for Vec<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnwindSafe for Vec<T, N>

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> 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, 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.