[−][src]Trait frame_support::storage::StorageLinkedMap
A strongly-typed linked map in storage.
Similar to StorageMap
but allows to enumerate other elements and doesn't implement append.
Details on implementation can be found at
[generator::StorageLinkedMap
]
Associated Types
type Query
The type that get/take return.
type Enumerator: Iterator<Item = (K, V)>
The type that iterates over all (key, value)
.
Required methods
fn contains_key<KeyArg: EncodeLike<K>>(key: KeyArg) -> bool
Does the value (explicitly) exist in storage?
fn get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
Load the value associated with the given key from the map.
fn swap<KeyArg1: EncodeLike<K>, KeyArg2: EncodeLike<K>>(
key1: KeyArg1,
key2: KeyArg2
)
key1: KeyArg1,
key2: KeyArg2
)
Swap the values of two keys.
fn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>(
key: KeyArg,
val: ValArg
)
key: KeyArg,
val: ValArg
)
Store a value to be associated with the given key from the map.
fn remove<KeyArg: EncodeLike<K>>(key: KeyArg)
Remove the value under a key.
fn mutate<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Self::Query) -> R>(
key: KeyArg,
f: F
) -> R
key: KeyArg,
f: F
) -> R
Mutate the value under a key.
fn take<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
Take the value under a key.
fn head() -> Option<K>
Return current head element.
fn enumerate() -> Self::Enumerator
Enumerate all elements in the map.
fn decode_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<usize, &'static str> where
V: DecodeLength + Len,
V: DecodeLength + Len,
Read the length of the value in a fast way, without decoding the entire value.
T
is required to implement Codec::DecodeLength
.
Note that 0
is returned as the default value if no encoded value exists at the given key.
Therefore, this function cannot be used as a sign of existence. use the ::contains_key()
function for this purpose.
fn translate<K2, V2, TK, TV>(
translate_key: TK,
translate_val: TV
) -> Result<(), Option<K2>> where
K2: FullCodec + Clone,
V2: Decode,
TK: Fn(K2) -> K,
TV: Fn(V2) -> V,
translate_key: TK,
translate_val: TV
) -> Result<(), Option<K2>> where
K2: FullCodec + Clone,
V2: Decode,
TK: Fn(K2) -> K,
TV: Fn(V2) -> V,
Translate the keys and values from some previous (K2, V2)
to the current type.
TK
translates keys from the old type, and TV
translates values.
Returns Err
if the map could not be interpreted as the old type, and Ok if it could.
The Err
contains the first key which could not be migrated, or None
if the
head of the list could not be read.
Warning
This function must be used with care, before being updated the storage still contains the
old type, thus other calls (such as get
) will fail at decoding it.
Usage
This would typically be called inside the module implementation of on_initialize, while
ensuring no usage of this storage are made before the call to on_initialize
. (More
precisely prior initialized modules doesn't make use of this storage).
Implementors
impl<K, V, G> StorageLinkedMap<K, V> for G where
K: FullCodec,
V: FullCodec,
G: StorageLinkedMap<K, V>,
[src]
K: FullCodec,
V: FullCodec,
G: StorageLinkedMap<K, V>,
type Query = G::Query
type Enumerator = Enumerator<K, V, G::KeyFormat>
fn contains_key<KeyArg: EncodeLike<K>>(key: KeyArg) -> bool
[src]
fn get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
[src]
fn swap<KeyArg1: EncodeLike<K>, KeyArg2: EncodeLike<K>>(
key1: KeyArg1,
key2: KeyArg2
)
[src]
key1: KeyArg1,
key2: KeyArg2
)
fn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>(
key: KeyArg,
val: ValArg
)
[src]
key: KeyArg,
val: ValArg
)
fn remove<KeyArg: EncodeLike<K>>(key: KeyArg)
[src]
fn mutate<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Self::Query) -> R>(
key: KeyArg,
f: F
) -> R
[src]
key: KeyArg,
f: F
) -> R
fn take<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
[src]
fn enumerate() -> Self::Enumerator
[src]
fn head() -> Option<K>
[src]
fn decode_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<usize, &'static str> where
V: DecodeLength + Len,
[src]
V: DecodeLength + Len,
fn translate<K2, V2, TK, TV>(
translate_key: TK,
translate_val: TV
) -> Result<(), Option<K2>> where
K2: FullCodec + Clone,
V2: Decode,
TK: Fn(K2) -> K,
TV: Fn(V2) -> V,
[src]
translate_key: TK,
translate_val: TV
) -> Result<(), Option<K2>> where
K2: FullCodec + Clone,
V2: Decode,
TK: Fn(K2) -> K,
TV: Fn(V2) -> V,
The translation happens in-place, new keys are inserted at the same time as old keys are removed, thus new keys must not collide with still remaining old keys.