Struct Stacko

Source
pub struct Stacko<T, K: Key = DefaultKey> { /* private fields */ }
Expand description

A Stacko for storing values of a single type.

Implementations§

Source§

impl<T, K: Key> Stacko<T, K>

Source

pub fn new() -> Self

Constructs an empty Stacko with a capacity of DEFAULT_CAPACITY.

Source

pub fn with_capacity(capacity: usize) -> Self

Constructs an empty Stacko able to store at least capacity values before needing to allocate.

Source

pub fn push(&self, value: T) -> (K, &T)

Pushes a value onto the Stacko potentially allocating more memory.

Source

pub fn try_push(&self, value: T) -> Result<(K, &T), T>

Tries to push a value onto the Stacko without allocating more memory.

§Errors

Fails in case no space is available in the Stacko.

Source

pub fn len(&self) -> usize

The number of values stored in the Stacko.

Source

pub fn is_empty(&self) -> bool

Checks whether the Stacko is empty.

Source

pub fn get(&self, key: K) -> Option<&T>

Returns a shared reference to the value stored for the given key.

The complexity is O(1) if the key has been returned by this Stacko. It is O(log n) if the key cannot be found or it has been serialized and deserialized without also serializing and deserializing the Stacko.

Source

pub fn get_mut(&mut self, key: K) -> Option<&mut T>

Returns an exclusive reference to the value stored for the given key.

For details see get.

Source

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

Returns a key corresponding to the provided index if a value is stored at the given index.

The complexity is O(log n).

Source

pub fn into_vec(self) -> Vec<T>

Turns the Stacko into a Vec.

The index of Key can be used as an index into the returned Vec.

Source

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

Returns an Iterator over the stored key-value pairs.

Trait Implementations§

Source§

impl<T: Clone, K: Clone + Key> Clone for Stacko<T, K>

Source§

fn clone(&self) -> Stacko<T, K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, K: Debug + Key> Debug for Stacko<T, K>

Source§

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

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

impl<T, K: Key> Default for Stacko<T, K>

Source§

fn default() -> Self

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

impl<T, K: Key> From<Stacko<T, K>> for Vec<T>

Source§

fn from(stacko: Stacko<T, K>) -> Self

Converts to this type from the input type.
Source§

impl<T, K: Key> From<Vec<T>> for Stacko<T, K>

Source§

fn from(chunk: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, K: Key> FromIterator<T> for Stacko<T, K>

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, K: Key> Index<K> for Stacko<T, K>

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, key: K) -> &Self::Output

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

impl<T, K: Key> IndexMut<K> for Stacko<T, K>

Source§

fn index_mut(&mut self, key: K) -> &mut Self::Output

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

impl<'p, T, K: Key> IntoIterator for &'p Stacko<T, K>

Source§

type Item = (K, &'p T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'p, T, K>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, K: Key> IntoIterator for Stacko<T, K>

Source§

type Item = (K, T)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, K>

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<T, K = DefaultKey> !Freeze for Stacko<T, K>

§

impl<T, K = DefaultKey> !RefUnwindSafe for Stacko<T, K>

§

impl<T, K> Send for Stacko<T, K>
where K: Send, T: Send,

§

impl<T, K = DefaultKey> !Sync for Stacko<T, K>

§

impl<T, K> Unpin for Stacko<T, K>
where K: Unpin, T: Unpin,

§

impl<T, K> UnwindSafe for Stacko<T, K>
where K: UnwindSafe, T: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.