Module near_sdk::collections[][src]

Expand description

Collections that offer an alternative to standard containers from std::collections::* by utilizing the underlying blockchain trie storage more efficiently.

For example, the following smart contract does not work with state efficiently, because it will load the entire HashMap at the beginning of the contract call, and will save it entirely at the end, in cases when there is state modification. This is fine for small number of elements, but very inefficient for large numbers.


#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct StatusMessage {
   records: HashMap<String, String>,
}

The following is an efficient alternative. It will load each element individually only when it is read and will save it only when it is written/removed.


#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct StatusMessage {
   records: LookupMap<String, String>,
}

The efficiency of LookupMap comes at the cost, since it has fewer methods than HashMap and is not that seemlessly integrated with the rest of the Rust standard library.

Structs

An persistent lazy option, that stores a value in the storage.

TreeMap based on AVL-tree

An non-iterable implementation of a map that stores its content directly on the trie.

An non-iterable implementation of a set that stores its content directly on the trie.

TreeMap based on AVL-tree

An iterable implementation of a map that stores its content directly on the trie.

An iterable implementation of a set that stores its content directly on the trie.

An iterable implementation of vector that stores its content on the trie. Uses the following map: index -> element.

Constants