Struct HyperMap

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

Source

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>
where K: Ord + Hash + Encode + Decode, V: Encode + Decode,

Source

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

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.

Source

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

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.

Source

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.

Source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + Ord + Encode + ToOwned<Owned = K> + ?Sized,

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.

Source

pub fn len(&self) -> u64

Returns the number of elements in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

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

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.

Source

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

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.

Trait Implementations§

Source§

impl<K, V> Default for HyperMap<K, V>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V> SpreadLayout for HyperMap<K, V>
where K: Ord + Hash + Encode + Decode, V: Encode + Decode,

Source§

fn read_ledger(key_prefix: &[u8], _: &[u8]) -> Self

从账本读数据接口
Source§

fn write_ledger(&self, key_prefix: &[u8], deploy_flag: &[u8])

写入账本数据接口,key为属性名

Auto Trait Implementations§

§

impl<K, V> Freeze for HyperMap<K, V>

§

impl<K, V> RefUnwindSafe for HyperMap<K, V>

§

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

§

impl<K, V> Sync for HyperMap<K, V>
where K: Sync, V: Sync,

§

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

§

impl<K, V> UnwindSafe for HyperMap<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.
Source§

impl<T> JsonSchemaMaybe for T