Struct ink_storage::collections::Stash[][src]

pub struct Stash<T> where
    T: PackedLayout
{ /* fields omitted */ }

A stash data structure operating on contract storage.

This allows to store information similar to a vector but in unordered fashion which enables constant time random deletion of elements. This allows for efficient attachment of data to some numeric indices.

Implementations

impl<T> Stash<T> where
    T: PackedLayout
[src]

pub fn new() -> Self[src]

Creates a new empty stash.

pub fn len(&self) -> u32[src]

Returns the number of elements stored in the stash.

pub fn is_empty(&self) -> bool[src]

Returns true if the stash contains no elements.

pub fn capacity(&self) -> u32[src]

Returns the number of entries the stash can hold without allocating another storage cell.

Note

This is the total number of occupied and vacant entries of the stash.

pub fn entries_key(&self) -> Option<&Key>[src]

Returns the underlying key to the cells.

Note

This is a low-level utility getter and should normally not be required by users.

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

Notable traits for Iter<'a, T>

impl<'a, T> Iterator for Iter<'a, T> where
    T: PackedLayout
type Item = &'a T;
[src]

Returns an iterator yielding shared references to all elements of the stash.

Note

Avoid unbounded iteration over big storage stashes. Prefer using methods like Iterator::take in order to limit the number of yielded elements.

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Notable traits for IterMut<'a, T>

impl<'a, T> Iterator for IterMut<'a, T> where
    T: PackedLayout
type Item = &'a mut T;
[src]

Returns an iterator yielding exclusive references to all elements of the stash.

Note

Avoid unbounded iteration over big storage stashes. Prefer using methods like Iterator::take in order to limit the number of yielded elements.

pub fn entries(&self) -> Entries<'_, T>[src]

Returns an iterator yielding shared references to all entries of the stash.

impl<T> Stash<T> where
    T: PackedLayout
[src]

pub fn get(&self, at: u32) -> Option<&T>[src]

Returns a shared reference to the element at the given index.

pub fn get_mut(&mut self, at: u32) -> Option<&mut T>[src]

Returns an exclusive reference to the element at the given index.

impl<T> Stash<T> where
    T: PackedLayout
[src]

pub fn put(&mut self, new_value: T) -> u32[src]

Put the element into the stash at the next vacant position.

Returns the stash index that the element was put into.

pub fn take(&mut self, at: u32) -> Option<T>[src]

Takes the element stored at the given index if any.

pub unsafe fn remove_occupied(&mut self, at: u32) -> Option<()>[src]

Removes the element stored at the given index if any.

This method acts similar to the take API and even still returns an Option. However, it guarantees to make no contract storage reads to the indexed element and will only write to its internal low-level lazy cache that the element at the given index is going to be removed at the end of the contract execution.

Calling this method with an index out of bounds for the returns None and does not remove the element, otherwise it returns Some(()).

Safety

The caller must ensure that at refers to an occupied index. Behavior is unspecified if at refers to a vacant index and could seriously damage the contract storage integrity.

pub fn defrag<C>(&mut self, max_iterations: Option<u32>, callback: C) -> u32 where
    C: FnMut(u32, u32, &T), 
[src]

Defragments the underlying storage to minimize footprint.

Returns the number of storage cells freed this way.

This might invalidate indices stored outside of the stash.

Callback

In order to keep those indices up-to-date the caller can provide a callback function that is called for every moved entry with a shared reference to the entries value and the old as well as the new index.

Note

  • If max_iterations is Some concrete value it is used in order to bound the number of iterations and won’t try to defrag until the stash is optimally compacted.
  • Users are advised to call this method using Some concrete value to keep gas costs within certain bounds.
  • The call to the given callback takes place before the reinsertion of the shifted occupied entry.

Trait Implementations

impl<T: Debug> Debug for Stash<T> where
    T: PackedLayout
[src]

impl<T> Default for StorageStash<T> where
    T: PackedLayout
[src]

impl<T> Drop for StorageStash<T> where
    T: PackedLayout
[src]

impl<T> Eq for StorageStash<T> where
    T: Decode + Eq + PackedLayout
[src]

impl<T> Extend<T> for StorageStash<T> where
    T: PackedLayout
[src]

impl<T> FromIterator<T> for StorageStash<T> where
    T: PackedLayout
[src]

impl<T> Index<u32> for StorageStash<T> where
    T: PackedLayout
[src]

type Output = T

The returned type after indexing.

impl<T> IndexMut<u32> for StorageStash<T> where
    T: PackedLayout
[src]

impl<'a, T: 'a> IntoIterator for &'a StorageStash<T> where
    T: PackedLayout
[src]

type Item = &'a T

The type of the elements being iterated over.

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?

impl<'a, T: 'a> IntoIterator for &'a mut StorageStash<T> where
    T: PackedLayout
[src]

type Item = &'a mut T

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T> PartialEq<Stash<T>> for StorageStash<T> where
    T: PartialEq + PackedLayout
[src]

impl<T> SpreadLayout for StorageStash<T> where
    T: PackedLayout
[src]

impl<T> StorageLayout for StorageStash<T> where
    T: PackedLayout + TypeInfo + 'static, 
[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Stash<T>

impl<T> Send for Stash<T> where
    T: Send

impl<T> !Sync for Stash<T>

impl<T> Unpin for Stash<T>

impl<T> !UnwindSafe for Stash<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,