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

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

Implementations

Create a new map. Use key_prefix as a unique prefix for keys.

Examples
use near_sdk::collections::LookupMap;
let mut map: LookupMap<String, String> = LookupMap::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 true if the map contains a given key.

Examples
use near_sdk::collections::LookupMap;

let mut map: LookupMap<String, String> = LookupMap::new(b"m");
assert_eq!(map.contains_key(&"Toyota".into()), false);

map.insert(&"Toyota".into(), &"Camry".into());
assert_eq!(map.contains_key(&"Toyota".into()), true);

Returns the value corresponding to the key.

Examples
use near_sdk::collections::LookupMap;

let mut map: LookupMap<String, String> = LookupMap::new(b"m");
assert_eq!(map.get(&"Toyota".into()), None);

map.insert(&"Toyota".into(), &"Camry".into());
assert_eq!(map.get(&"Toyota".into()), Some("Camry".into()));

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::LookupMap;

let mut map: LookupMap<String, String> = LookupMap::new(b"m");
assert_eq!(map.remove(&"Toyota".into()), None);

map.insert(&"Toyota".into(), &"Camry".into());
assert_eq!(map.remove(&"Toyota".into()), Some("Camry".into()));

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::LookupMap;

let mut map: LookupMap<String, String> = LookupMap::new(b"m");
assert_eq!(map.insert(&"Toyota".into(), &"Camry".into()), None);
assert_eq!(map.insert(&"Toyota".into(), &"Corolla".into()), Some("Camry".into()));

Inserts all new key-values from the iterator and replaces values with existing keys with new values returned from the iterator.

Examples
use near_sdk::collections::LookupMap;

let mut extendee: LookupMap<String, String> = LookupMap::new(b"m");
let mut source = vec![];

source.push(("Toyota".into(), "Camry".into()));
source.push(("Nissan".into(), "Almera".into()));
source.push(("Ford".into(), "Mustang".into()));
source.push(("Chevrolet".into(), "Camaro".into()));
extendee.extend(source.into_iter());

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

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.