Struct StackMapping

Source
pub struct StackMapping<Key: Offset + Copy + Debug, T: Copy + Debug> { /* private fields */ }
Expand description

A combination of a BoundedVector and an Array.

This provides Vec-like semantics with elements of type Key. Additionally, each key is associated with one value of type T (key is mapped to value). The value can be looked up in constant time using the index operator ([]).

Implementations§

Source§

impl<Key: Offset + Copy + Debug, T: Copy + Debug> StackMapping<Key, T>

Source

pub fn with_array_value_size_stack_size( array_value: T, array_size: usize, stack_size: usize, ) -> StackMapping<Key, T>

Construct a new StackMapping.

§Parameters
  • array_value: see default_value
  • array_size: the size of the array, must be large enough to hold the highest expected value of type Key
  • stack_size: the maximum size of the stack, e.g. the maximum number of keys that can be added to this stackmapping
Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

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

This removs the top Key and also resets the mapping of this key to the default_value.

Source

pub fn peek(&self) -> Key

Returns the last key in the vector.

§Panics

Panics if the vector is empty.

Source

pub fn clear(&mut self)

This clears the vector and resets all mappings.

Source

pub fn stack_at(&self, offset: usize) -> Key

Returns the key in the vector at the given index.

Source

pub fn stack_at_mut(&mut self, offset: usize) -> &mut Key

Returns the mutable key in the vector at the given index.

Source

pub fn push(&mut self, key: Key, value: T)

Pushes to the vector and maps key to value.

Source

pub fn push_but_do_not_set(&mut self, key: Key)

Pushes to the vector.

Source

pub fn set_but_do_not_push(&mut self, key: Key, value: T)

Maps key to value.

Source

pub fn iter(&self) -> Iter<'_, Key>

Returns an iterator over the keys in the vector.

Source§

impl<Key: Ord + Offset + Copy + Debug, T: Copy + Debug> StackMapping<Key, T>

Source§

impl<Key: Offset + Copy + Debug, T: Copy + Debug> StackMapping<Key, T>

Source

pub fn sort_unstable_by_key<F, K>(&mut self, f: F)
where F: FnMut(&Key) -> K, K: Ord,

Trait Implementations§

Source§

impl<Key: Debug + Offset + Copy + Debug, T: Debug + Copy + Debug> Debug for StackMapping<Key, T>

Source§

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

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

impl<Key: Default + Offset + Copy + Debug, T: Default + Copy + Debug> Default for StackMapping<Key, T>

Source§

fn default() -> StackMapping<Key, T>

Returns the “default value” for a type. Read more
Source§

impl<Key: Offset + Copy + Debug, T: Copy + Debug> HeapSpace for StackMapping<Key, T>

Source§

fn heap_space(&self) -> usize

The number of bytes allocated on the heap that this owns.
Source§

impl<Key: Offset + Copy + Debug, T: Copy + Debug> Index<Key> for StackMapping<Key, T>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: Key) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, Key: Offset + Copy + Debug, T: Copy + Debug> IntoIterator for &'a StackMapping<Key, T>

Source§

type Item = &'a Key

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Key>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<Key, T> Freeze for StackMapping<Key, T>
where T: Freeze,

§

impl<Key, T> RefUnwindSafe for StackMapping<Key, T>

§

impl<Key, T> Send for StackMapping<Key, T>
where T: Send, Key: Send,

§

impl<Key, T> Sync for StackMapping<Key, T>
where T: Sync, Key: Sync,

§

impl<Key, T> Unpin for StackMapping<Key, T>
where T: Unpin, Key: Unpin,

§

impl<Key, T> UnwindSafe for StackMapping<Key, T>
where T: UnwindSafe, Key: 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.