pub trait IterableStorageMap<K: FullEncode, V: FullCodec>: StorageMap<K, V> {
    type Iterator: Iterator<Item = (K, V)>;
    type KeyIterator: Iterator<Item = K>;

    // Required methods
    fn iter() -> Self::Iterator;
    fn iter_from(starting_raw_key: Vec<u8>) -> Self::Iterator;
    fn iter_keys() -> Self::KeyIterator;
    fn iter_keys_from(starting_raw_key: Vec<u8>) -> Self::KeyIterator;
    fn drain() -> Self::Iterator;
    fn translate<O: Decode, F: FnMut(K, O) -> Option<V>>(f: F);
    fn translate_next<O: Decode, F: FnMut(K, O) -> Option<V>>(
        previous_key: Option<Vec<u8>>,
        f: F
    ) -> Option<Vec<u8>>;
}
Expand description

A strongly-typed map in storage whose keys and values can be iterated over.

Required Associated Types§

source

type Iterator: Iterator<Item = (K, V)>

The type that iterates over all (key, value).

source

type KeyIterator: Iterator<Item = K>

The type that itereates over all keys.

Required Methods§

source

fn iter() -> Self::Iterator

Enumerate all elements in the map in lexicographical order of the encoded key. If you alter the map while doing this, you’ll get undefined results.

source

fn iter_from(starting_raw_key: Vec<u8>) -> Self::Iterator

Enumerate all elements in the map after a specified starting_raw_key in lexicographical order of the encoded key. If you alter the map while doing this, you’ll get undefined results.

source

fn iter_keys() -> Self::KeyIterator

Enumerate all keys in the map in lexicographical order of the encoded key, skipping over the elements. If you alter the map while doing this, you’ll get undefined results.

source

fn iter_keys_from(starting_raw_key: Vec<u8>) -> Self::KeyIterator

Enumerate all keys in the map after a specified starting_raw_key in lexicographical order of the encoded key. If you alter the map while doing this, you’ll get undefined results.

source

fn drain() -> Self::Iterator

Remove all elements from the map and iterate through them in lexicographical order of the encoded key. If you add elements to the map while doing this, you’ll get undefined results.

source

fn translate<O: Decode, F: FnMut(K, O) -> Option<V>>(f: F)

Translate the values of all elements by a function f, in the map in lexicographical order of the encoded key. By returning None from f for an element, you’ll remove it from the map.

NOTE: If a value fail to decode because storage is corrupted then it is skipped.

source

fn translate_next<O: Decode, F: FnMut(K, O) -> Option<V>>( previous_key: Option<Vec<u8>>, f: F ) -> Option<Vec<u8>>

Translate the next entry following previous_key by a function f. By returning None from f for an element, you’ll remove it from the map.

Returns the next key to iterate from in lexicographical order of the encoded key.

Implementors§

source§

impl<K: FullCodec, V: FullCodec, G: StorageMap<K, V>> IterableStorageMap<K, V> for Gwhere G::Hasher: ReversibleStorageHasher,