Struct LookupMap

Source
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:

Implementations§

Source§

impl<K, V> LookupMap<K, V>

Source

pub fn new(prefix: Vec<u8>) -> Self

Creates a new map. Uses prefix as a unique prefix for keys.

Source

pub fn get_prefix(&self) -> &Box<[u8]>

Returns the unique byte prefix used for key generation in the LookupSet.

Source

pub fn set(&mut self, key: K, value: Option<V>)

Inserts or removes a key-value to the map.

  • If value is None then the specified key is removed.
  • If value is Some(v) then v is inserted by the specified key
Source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: BorshSerialize + ToOwned<Owned = K> + ?Sized,

Returns a reference to the value corresponding to the key.

If the map doesn’t have the key present, returns None

Source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: BorshSerialize + ToOwned<Owned = K> + ?Sized,

Returns a mutable reference to the value corresponding to the key.

If the map doesn’t have the key present, returns None

Source

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.

Source

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.

Source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: BorshSerialize + ToOwned<Owned = K> + ?Sized,

Returns true if the map contains a value for the specified key.

Source

pub fn flush(&mut self)

Writes the cached operations to the persistent storage.

§Panic

Panics if serialization fails

Trait Implementations§

Source§

impl<K, V> BorshDeserialize for LookupMap<K, V>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

impl<K, V> BorshSerialize for LookupMap<K, V>

Source§

fn serialize<W: Write>(&self, writer: &mut W) -> Result<(), Error>

Source§

fn try_to_vec(&self) -> Result<Vec<u8>, Error>

Serialize this instance into a vector of bytes.
Source§

impl<K, V> Drop for LookupMap<K, V>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<K, V> Extend<(K, V)> for LookupMap<K, V>

Source§

fn extend<I>(&mut self, iter: I)
where I: IntoIterator<Item = (K, V)>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K, V, Q> Index<&Q> for LookupMap<K, V>

Source§

type Output = V

The returned type after indexing.
Source§

fn index(&self, index: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<K, V> !Freeze for LookupMap<K, V>

§

impl<K, V> !RefUnwindSafe for LookupMap<K, V>

§

impl<K, V> Send for LookupMap<K, V>
where K: Send, V: Send,

§

impl<K, V> !Sync for LookupMap<K, V>

§

impl<K, V> Unpin for LookupMap<K, V>

§

impl<K, V> UnwindSafe for LookupMap<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.