Trait frame_support::storage::StorageMap
source · pub trait StorageMap<K: FullEncode, V: FullCodec> {
type Query;
Show 19 methods
// Required methods
fn hashed_key_for<KeyArg: EncodeLike<K>>(key: KeyArg) -> Vec<u8> ⓘ;
fn contains_key<KeyArg: EncodeLike<K>>(key: KeyArg) -> bool;
fn get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query;
fn set<KeyArg: EncodeLike<K>>(key: KeyArg, query: Self::Query);
fn try_get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<V, ()>;
fn swap<KeyArg1: EncodeLike<K>, KeyArg2: EncodeLike<K>>(
key1: KeyArg1,
key2: KeyArg2,
);
fn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>(
key: KeyArg,
val: ValArg,
);
fn remove<KeyArg: EncodeLike<K>>(key: KeyArg);
fn mutate<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Self::Query) -> R>(
key: KeyArg,
f: F,
) -> R;
fn try_mutate<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Self::Query) -> Result<R, E>>(
key: KeyArg,
f: F,
) -> Result<R, E>;
fn mutate_exists<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Option<V>) -> R>(
key: KeyArg,
f: F,
) -> R;
fn try_mutate_exists<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Option<V>) -> Result<R, E>>(
key: KeyArg,
f: F,
) -> Result<R, E>;
fn take<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query;
fn append<Item, EncodeLikeItem, EncodeLikeKey>(
key: EncodeLikeKey,
item: EncodeLikeItem,
)
where EncodeLikeKey: EncodeLike<K>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>;
fn migrate_key<OldHasher: StorageHasher, KeyArg: EncodeLike<K>>(
key: KeyArg,
) -> Option<V>;
// Provided methods
fn mutate_extant<KeyArg: EncodeLike<K>, R: Default, F: FnOnce(&mut V) -> R>(
key: KeyArg,
f: F,
) -> R { ... }
fn decode_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>
where V: StorageDecodeLength { ... }
fn decode_non_dedup_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>
where V: StorageDecodeNonDedupLength { ... }
fn migrate_key_from_blake<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<V> { ... }
}
Expand description
A strongly-typed map in storage.
Details on implementation can be found at [generator::StorageMap
].
Required Associated Types§
Required Methods§
sourcefn hashed_key_for<KeyArg: EncodeLike<K>>(key: KeyArg) -> Vec<u8> ⓘ
fn hashed_key_for<KeyArg: EncodeLike<K>>(key: KeyArg) -> Vec<u8> ⓘ
Get the storage key used to fetch a value corresponding to a specific key.
sourcefn contains_key<KeyArg: EncodeLike<K>>(key: KeyArg) -> bool
fn contains_key<KeyArg: EncodeLike<K>>(key: KeyArg) -> bool
Does the value (explicitly) exist in storage?
sourcefn get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
fn get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
Load the value associated with the given key from the map.
sourcefn set<KeyArg: EncodeLike<K>>(key: KeyArg, query: Self::Query)
fn set<KeyArg: EncodeLike<K>>(key: KeyArg, query: Self::Query)
Store or remove the value to be associated with key
so that get
returns the query
.
sourcefn try_get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<V, ()>
fn try_get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<V, ()>
Try to get the value for the given key from the map.
Returns Ok
if it exists, Err
if not.
sourcefn swap<KeyArg1: EncodeLike<K>, KeyArg2: EncodeLike<K>>(
key1: KeyArg1,
key2: KeyArg2,
)
fn swap<KeyArg1: EncodeLike<K>, KeyArg2: EncodeLike<K>>( key1: KeyArg1, key2: KeyArg2, )
Swap the values of two keys.
sourcefn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>(
key: KeyArg,
val: ValArg,
)
fn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>( key: KeyArg, val: ValArg, )
Store a value to be associated with the given key from the map.
sourcefn remove<KeyArg: EncodeLike<K>>(key: KeyArg)
fn remove<KeyArg: EncodeLike<K>>(key: KeyArg)
Remove the value under a key.
sourcefn mutate<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Self::Query) -> R>(
key: KeyArg,
f: F,
) -> R
fn mutate<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Self::Query) -> R>( key: KeyArg, f: F, ) -> R
Mutate the value under a key.
sourcefn try_mutate<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Self::Query) -> Result<R, E>>(
key: KeyArg,
f: F,
) -> Result<R, E>
fn try_mutate<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Self::Query) -> Result<R, E>>( key: KeyArg, f: F, ) -> Result<R, E>
Mutate the item, only if an Ok
value is returned.
sourcefn mutate_exists<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Option<V>) -> R>(
key: KeyArg,
f: F,
) -> R
fn mutate_exists<KeyArg: EncodeLike<K>, R, F: FnOnce(&mut Option<V>) -> R>( key: KeyArg, f: F, ) -> R
Mutate the value under a key.
Deletes the item if mutated to a None
.
sourcefn try_mutate_exists<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Option<V>) -> Result<R, E>>(
key: KeyArg,
f: F,
) -> Result<R, E>
fn try_mutate_exists<KeyArg: EncodeLike<K>, R, E, F: FnOnce(&mut Option<V>) -> Result<R, E>>( key: KeyArg, f: F, ) -> Result<R, E>
Mutate the item, only if an Ok
value is returned. Deletes the item if mutated to a None
.
f
will always be called with an option representing if the storage item exists (Some<V>
)
or if the storage item does not exist (None
), independent of the QueryType
.
sourcefn take<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
fn take<KeyArg: EncodeLike<K>>(key: KeyArg) -> Self::Query
Take the value under a key.
sourcefn append<Item, EncodeLikeItem, EncodeLikeKey>(
key: EncodeLikeKey,
item: EncodeLikeItem,
)where
EncodeLikeKey: EncodeLike<K>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>,
fn append<Item, EncodeLikeItem, EncodeLikeKey>(
key: EncodeLikeKey,
item: EncodeLikeItem,
)where
EncodeLikeKey: EncodeLike<K>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>,
Append the given items to the value in the storage.
V
is required to implement codec::EncodeAppend
.
§Warning
If the storage item is not encoded properly, the storage will be overwritten
and set to [item]
. Any default value set for the storage item will be ignored
on overwrite.
sourcefn migrate_key<OldHasher: StorageHasher, KeyArg: EncodeLike<K>>(
key: KeyArg,
) -> Option<V>
fn migrate_key<OldHasher: StorageHasher, KeyArg: EncodeLike<K>>( key: KeyArg, ) -> Option<V>
Migrate an item with the given key
from a defunct OldHasher
to the current hasher.
If the key doesn’t exist, then it’s a no-op. If it does, then it returns its value.
Provided Methods§
sourcefn mutate_extant<KeyArg: EncodeLike<K>, R: Default, F: FnOnce(&mut V) -> R>(
key: KeyArg,
f: F,
) -> R
fn mutate_extant<KeyArg: EncodeLike<K>, R: Default, F: FnOnce(&mut V) -> R>( key: KeyArg, f: F, ) -> R
Mutate the value under a key if the value already exists. Do nothing and return the default value if not.
sourcefn decode_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>where
V: StorageDecodeLength,
fn decode_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>where
V: StorageDecodeLength,
Read the length of the storage value without decoding the entire value under the
given key
.
V
is required to implement StorageDecodeLength
.
If the value does not exists or it fails to decode the length, None
is returned.
Otherwise Some(len)
is returned.
§Warning
None
does not mean that get()
does not return a value. The default value is completely
ignored by this function.
sourcefn decode_non_dedup_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>where
V: StorageDecodeNonDedupLength,
fn decode_non_dedup_len<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<usize>where
V: StorageDecodeNonDedupLength,
Read the length of the storage value without decoding the entire value.
V
is required to implement StorageDecodeNonDedupLength
.
If the value does not exists or it fails to decode the length, None
is returned.
Otherwise Some(len)
is returned.
§Warning
-
None
does not mean thatget()
does not return a value. The default value is completely ignored by this function. -
The value returned is the non-deduplicated length of the underlying Vector in storage.This means that any duplicate items are included.
sourcefn migrate_key_from_blake<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<V>
fn migrate_key_from_blake<KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<V>
Migrate an item with the given key
from a blake2_256
hasher to the current hasher.
If the key doesn’t exist, then it’s a no-op. If it does, then it returns its value.