pub struct HashMap<K, V, H = Blake2x256> where
    K: Ord + Clone + PackedLayout,
    V: PackedLayout,
    H: CryptoHash,
    Key: From<<H as HashOutput>::Type>, 
{ /* private fields */ }
Expand description

A hash map operating on the contract storage.

Stores a mapping between keys and values.

Note

Unlike Rust’s standard HashMap that uses the core::hash::Hash trait in order to hash its keys the storage hash map uses the [scale::Encode] encoding in order to hash its keys using a built-in cryptographic hash function provided by the chain runtime.

The main difference between the lower-level LazyHashMap and the storage::HashMap is that the latter is aware of its associated keys and values and operates on those instances directly as opposed to Option instances of them. Also it provides a more high-level and user focused API.

Users should generally prefer using this storage hash map over the low-level LazyHashMap for direct usage in their smart contracts.

Implementations

Creates a new empty storage hash map.

Returns the number of key-value pairs stored in the hash map.

Returns true if the hash map is empty.

Returns an iterator yielding shared references to all key/value pairs of the hash map.

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

Returns an iterator yielding exclusive references to all key/value pairs of the hash map.

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

Returns an iterator yielding shared references to all values of the hash map.

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

Returns an iterator yielding shared references to all values of the hash map.

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

Returns an iterator yielding shared references to all keys of the hash map.

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

Inserts a key-value pair into the map.

Returns the previous value associated with the same key if any. If the map did not have this key present, None is returned.

Note
  • If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical.

Removes the key/value pair from the map associated with the given key.

  • Returns the removed value if any.
Note

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Returns a shared reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Returns true if there is an entry corresponding to the key in the map.

Defragments storage used by the storage hash map.

Returns the number of storage cells freed this way.

A max_iterations parameter of None means that there is no limit to the number of iterations performed. This is generally not advised.

Note

This frees storage that is held but not necessary for the hash map to hold. This operation might be expensive, especially for big max_iteration parameters. The max_iterations parameter can be used to limit the expensiveness for this operation and instead free up storage incrementally.

Gets the given key’s corresponding entry in the map for in-place manipulation.

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.