Struct ink_storage::collections::Stash
source · [−]pub struct Stash<T> where
T: PackedLayout, { /* private fields */ }
Expand description
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
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.
Returns the underlying key to the cells.
Note
This is a low-level utility getter and should normally not be required by users.
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.
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.
Put the element into the stash at the next vacant position.
Returns the stash index that the element was put into.
Takes the element stored at the given index if any.
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.
Defragments the underlying storage to minimize footprint.
Returns the number of storage cells freed this way.
This might invalidate indices stored outside 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
isSome
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
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more
Default initializes the implementing type using spread layout. Read more
Pulls an instance of Self
from the contract storage. Read more
Pushes an instance of Self
to the contract storage. Read more
Clears an instance of Self
from the contract storage. Read more
Indicates whether a type requires deep clean-up of its state meaning that
a clean-up routine has to decode an entity into an instance in order to
eventually recurse upon its tear-down.
This is not required for the majority of primitive data types such as i32
,
however types such as storage::Box
that might want to forward the clean-up
procedure to their inner T
require a deep clean-up. Read more