Struct IndexMap

Source
pub struct IndexMap<K: Borrow<usize> + Default, V, const N: usize> { /* private fields */ }
Expand description

This is a fixed-size map that can store up to N consecutive elements.

Implementations§

Source§

impl<K: Borrow<usize> + Default, V, const N: usize> IndexMap<K, V, N>

Source

pub const fn new() -> Self

Create a new IndexMap.

Returns a new IndexMap.

Source

pub fn get(&self, index: &K) -> Option<&V>

Get the element at the given index.

index - The index to get the element from.

Returns Some(&T) if the index is in-bounds, otherwise None.

Source

pub fn get_mut(&mut self, index: &K) -> Option<&mut V>

Get a mutable reference to the element at the given index.

index - The index to get the element from.

Returns Some(&mut T) if the index is in-bounds, otherwise None.

Source

pub fn insert(&mut self, index: &K, value: V) -> Result<(), KernelError>

Insert a value at the given index.

index - The index to insert the value at. value - The value to insert.

Returns Ok(()) if the index was in-bounds, otherwise Err(KernelError::OutOfMemory).

Source

pub fn insert_next(&mut self, value: V) -> Result<usize, KernelError>

Insert a value at the next available index.

value - The value to insert.

Returns Ok(index) if the value was inserted, otherwise Err(KernelError::OutOfMemory).

Source

pub fn remove(&mut self, index: &K) -> Option<V>

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 iter(&self) -> impl Iterator<Item = &Option<V>>

Get an iterator over the elements in the map.

Returns an iterator over the elements in the map.

Source

pub fn iter_from_cycle(&self, index: &K) -> impl Iterator<Item = &Option<V>>

Get an cycling iterator over the elements in the map, starting from the given index.

index - The index to start the iterator from.

Returns an iterator over the elements in the map.

Source

pub fn next(&self, index: Option<&K>) -> Option<usize>

Get the next index that contains a value (this will cycle).

index - The index to start the search from.

Returns the next index (potentially < index) that contains a value, otherwise None.

Source

pub fn find_empty(&self) -> Option<usize>

Auto Trait Implementations§

§

impl<K, V, const N: usize> Freeze for IndexMap<K, V, N>
where V: Freeze,

§

impl<K, V, const N: usize> RefUnwindSafe for IndexMap<K, V, N>

§

impl<K, V, const N: usize> Send for IndexMap<K, V, N>
where K: Send, V: Send,

§

impl<K, V, const N: usize> Sync for IndexMap<K, V, N>
where K: Sync, V: Sync,

§

impl<K, V, const N: usize> Unpin for IndexMap<K, V, N>
where K: Unpin, V: Unpin,

§

impl<K, V, const N: usize> UnwindSafe for IndexMap<K, V, N>
where K: UnwindSafe, V: 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> 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.
§

impl<T> ThreadArgument for T
where T: Send + 'static,