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

Creates a new empty stash.

Returns the number of elements stored in the stash.

Returns true if the stash contains no elements.

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.

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

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

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

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 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

Formats the value using the given formatter. Read more

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

Executes the destructor for this type. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Creates a value from an iterator. Read more

The returned type after indexing.

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

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Default initializes the implementing type using spread layout. Read more

The footprint of the type. 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

Returns the static storage layout of Self. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.