pub struct HyperMap<K, V> { /* private fields */ }
Expand description
An non-iterable implementation of a map that stores its content directly on the trie.
Implementations§
Source§impl<K, V> HyperMap<K, V>
impl<K, V> HyperMap<K, V>
Sourcepub fn new() -> Self
pub fn new() -> Self
Make a new, empty HyperMap
,
It should be called when contract init.
§Examples
Basic usage:
use fvm_std::collections::hyper_map::HyperMap;
use fvm_macros::contract;
use fvm_macros::storage;
#[storage]
pub struct HyperMapDemo {
map: HyperMap<String, String>,
}
#[contract]
impl HyperMapDemo {
/// used in construct method
fn new() -> Self {
Self { map: HyperMap::new() }
}
}
Source§impl<K, V> HyperMap<K, V>
impl<K, V> HyperMap<K, V>
Sourcepub fn get<Q>(&mut self, k: &Q) -> Option<&V>
pub fn get<Q>(&mut self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
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 the ordering on the borrowed form must match the ordering on the key type.
All get_mut
result we wil think it to be changed.
Sourcepub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Clone,
pub fn insert(&mut self, key: K, value: V) -> Option<V>where
K: Clone,
Inserts a key-value pair into the map.
If the map did not have this key present, None
is returned.
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. See the [module-level
documentation] for more.
Sourcepub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
Removes a key from the map, returning the stored key and value if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn get_key_value<Q>(&mut self, k: &Q) -> Option<(&K, &V)>
pub fn get_key_value<Q>(&mut self, k: &Q) -> Option<(&K, &V)>
Returns the key-value pair corresponding to the supplied key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.
Sourcepub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn contains_key<Q>(&self, k: &Q) -> bool
Returns true
if the map contains a value for the specified key.
The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.