pub struct LookupMap<K, V>{ /* private fields */ }Expand description
An implementation of a map that stores its content directly on the persistent storage.
All operations are cached. The cache is flushed in the following cases:
Self::flushmethod is calleddropmethod is called
Implementations§
Source§impl<K, V> LookupMap<K, V>
impl<K, V> LookupMap<K, V>
Sourcepub fn new(prefix: Vec<u8>) -> Self
pub fn new(prefix: Vec<u8>) -> Self
Creates a new map. Uses prefix as a unique prefix for keys.
Sourcepub fn get_prefix(&self) -> &Box<[u8]>
pub fn get_prefix(&self) -> &Box<[u8]>
Returns the unique byte prefix used for key generation in the LookupSet.
Sourcepub fn set(&mut self, key: K, value: Option<V>)
pub fn set(&mut self, key: K, value: Option<V>)
Inserts or removes a key-value to the map.
- If
valueisNonethen the specified key is removed. - If
valueisSome(v)thenvis inserted by the specified key
Sourcepub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
Returns a reference to the value corresponding to the key.
If the map doesn’t have the key present, returns None
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.
If the map doesn’t have the key present, returns None
Sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>where
K: Clone,
pub fn insert(&mut self, k: K, v: 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.
Sourcepub fn remove(&mut self, k: K) -> Option<V>where
K: Clone,
pub fn remove(&mut self, k: K) -> Option<V>where
K: Clone,
Removes a key from the map, returning the value at the key if the key was previously in the map.
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.
Trait Implementations§
Source§impl<K, V> BorshDeserialize for LookupMap<K, V>
impl<K, V> BorshDeserialize for LookupMap<K, V>
Source§impl<K, V> BorshSerialize for LookupMap<K, V>
impl<K, V> BorshSerialize for LookupMap<K, V>
Source§impl<K, V> Extend<(K, V)> for LookupMap<K, V>
impl<K, V> Extend<(K, V)> for LookupMap<K, V>
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (K, V)>,
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)