pub struct UnorderedMap<K, V> { /* private fields */ }
Expand description

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

Implementations

Returns the number of elements in the map, also referred to as its size.

Examples
use near_sdk::collections::UnorderedMap;

let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");
assert_eq!(map.len(), 0);
map.insert(&1, &1);
map.insert(&2, &2);
assert_eq!(map.len(), 2);

Returns true if the map contains no elements.

Create new map with zero elements. Use prefix as a unique identifier.

Examples
use near_sdk::collections::UnorderedMap;
let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");

Inserts a serialized key-value pair into the map. If the map did not have this key present, None is returned. Otherwise returns a serialized value. Note, the keys that have the same hash value are undistinguished by the implementation.

Removes a serialized key from the map, returning the serialized value at the key if the key was previously in the map.

Returns the value corresponding to the key.

Examples
use near_sdk::collections::UnorderedMap;

let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");
assert_eq!(map.get(&1), None);
map.insert(&1, &10);
assert_eq!(map.get(&1), Some(10));

Removes a key from the map, returning the value at the key if the key was previously in the map.

Examples
use near_sdk::collections::UnorderedMap;

let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");
assert_eq!(map.remove(&1), None);
map.insert(&1, &10);
assert_eq!(map.remove(&1), Some(10));
assert_eq!(map.len(), 0);

Inserts a key-value pair into the map. If the map did not have this key present, None is returned. Otherwise returns a value. Note, the keys that have the same hash value are undistinguished by the implementation.

Examples
use near_sdk::collections::UnorderedMap;

let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");
map.insert(&1, &10);
assert_eq!(map.get(&1), Some(10));
assert_eq!(map.len(), 1);

Clears the map, removing all elements.

Examples
use near_sdk::collections::UnorderedMap;

let mut map: UnorderedMap<u8, u8> = UnorderedMap::new(b"m");
map.insert(&1, &10);
map.insert(&2, &20);
map.clear();
assert_eq!(map.len(), 0);

Copies elements into an std::vec::Vec.

An iterator visiting all keys. The iterator element type is K.

An iterator visiting all values. The iterator element type is V.

Iterate over deserialized keys and values.

Returns a view of keys as a vector. It’s sometimes useful to have random access to the keys.

Returns a view of values as a vector. It’s sometimes useful to have random access to the values.

Trait Implementations

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more
Deserialize this instance from a slice of bytes.
Serialize this instance into a vector of bytes.
Formats the value using the given formatter. 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

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.