pub trait StorageMap<K, V>where
K: FullEncode,
V: FullCodec,{
type Query;
Show 17 methods
fn hashed_key_for<KeyArg>(key: KeyArg) -> Vec<u8, Global> ⓘ
where
KeyArg: EncodeLike<K>;
fn contains_key<KeyArg>(key: KeyArg) -> bool
where
KeyArg: EncodeLike<K>;
fn get<KeyArg>(key: KeyArg) -> Self::Query
where
KeyArg: EncodeLike<K>;
fn set<KeyArg>(key: KeyArg, query: Self::Query)
where
KeyArg: EncodeLike<K>;
fn try_get<KeyArg>(key: KeyArg) -> Result<V, ()>
where
KeyArg: EncodeLike<K>;
fn swap<KeyArg1, KeyArg2>(key1: KeyArg1, key2: KeyArg2)
where
KeyArg1: EncodeLike<K>,
KeyArg2: EncodeLike<K>;
fn insert<KeyArg, ValArg>(key: KeyArg, val: ValArg)
where
KeyArg: EncodeLike<K>,
ValArg: EncodeLike<V>;
fn remove<KeyArg>(key: KeyArg)
where
KeyArg: EncodeLike<K>;
fn mutate<KeyArg, R, F>(key: KeyArg, f: F) -> R
where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> R;
fn try_mutate<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> Result<R, E>;
fn mutate_exists<KeyArg, R, F>(key: KeyArg, f: F) -> R
where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> R;
fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>
where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> Result<R, E>;
fn take<KeyArg>(key: KeyArg) -> Self::Query
where
KeyArg: EncodeLike<K>;
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, KeyArg>(key: KeyArg) -> Option<V>
where
OldHasher: StorageHasher,
KeyArg: EncodeLike<K>;
fn decode_len<KeyArg>(key: KeyArg) -> Option<usize>
where
KeyArg: EncodeLike<K>,
V: StorageDecodeLength,
{ ... }
fn migrate_key_from_blake<KeyArg>(key: KeyArg) -> Option<V>
where
KeyArg: EncodeLike<K>,
{ ... }
}
Expand description
A strongly-typed map in storage.
Details on implementation can be found at [generator::StorageMap
].
Required Associated Types§
type Query
type Query
The type that get/take return.
Required Methods§
fn hashed_key_for<KeyArg>(key: KeyArg) -> Vec<u8, Global> ⓘwhere
KeyArg: EncodeLike<K>,
fn hashed_key_for<KeyArg>(key: KeyArg) -> Vec<u8, Global> ⓘwhere
KeyArg: EncodeLike<K>,
Get the storage key used to fetch a value corresponding to a specific key.
fn contains_key<KeyArg>(key: KeyArg) -> boolwhere
KeyArg: EncodeLike<K>,
fn contains_key<KeyArg>(key: KeyArg) -> boolwhere
KeyArg: EncodeLike<K>,
Does the value (explicitly) exist in storage?
fn get<KeyArg>(key: KeyArg) -> Self::Querywhere
KeyArg: EncodeLike<K>,
fn get<KeyArg>(key: KeyArg) -> Self::Querywhere
KeyArg: EncodeLike<K>,
Load the value associated with the given key from the map.
fn set<KeyArg>(key: KeyArg, query: Self::Query)where
KeyArg: EncodeLike<K>,
fn set<KeyArg>(key: KeyArg, query: Self::Query)where
KeyArg: EncodeLike<K>,
Store or remove the value to be associated with key
so that get
returns the query
.
fn try_get<KeyArg>(key: KeyArg) -> Result<V, ()>where
KeyArg: EncodeLike<K>,
fn try_get<KeyArg>(key: KeyArg) -> Result<V, ()>where
KeyArg: EncodeLike<K>,
Try to get the value for the given key from the map.
Returns Ok
if it exists, Err
if not.
fn swap<KeyArg1, KeyArg2>(key1: KeyArg1, key2: KeyArg2)where
KeyArg1: EncodeLike<K>,
KeyArg2: EncodeLike<K>,
fn swap<KeyArg1, KeyArg2>(key1: KeyArg1, key2: KeyArg2)where
KeyArg1: EncodeLike<K>,
KeyArg2: EncodeLike<K>,
Swap the values of two keys.
fn insert<KeyArg, ValArg>(key: KeyArg, val: ValArg)where
KeyArg: EncodeLike<K>,
ValArg: EncodeLike<V>,
fn insert<KeyArg, ValArg>(key: KeyArg, val: ValArg)where
KeyArg: EncodeLike<K>,
ValArg: EncodeLike<V>,
Store a value to be associated with the given key from the map.
fn remove<KeyArg>(key: KeyArg)where
KeyArg: EncodeLike<K>,
fn remove<KeyArg>(key: KeyArg)where
KeyArg: EncodeLike<K>,
Remove the value under a key.
fn mutate<KeyArg, R, F>(key: KeyArg, f: F) -> Rwhere
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> R,
fn mutate<KeyArg, R, F>(key: KeyArg, f: F) -> Rwhere
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> R,
Mutate the value under a key.
fn try_mutate<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> Result<R, E>,
fn try_mutate<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Self::Query) -> Result<R, E>,
Mutate the item, only if an Ok
value is returned.
fn mutate_exists<KeyArg, R, F>(key: KeyArg, f: F) -> Rwhere
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> R,
fn mutate_exists<KeyArg, R, F>(key: KeyArg, f: F) -> Rwhere
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> R,
Mutate the value under a key.
Deletes the item if mutated to a None
.
fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> Result<R, E>,
fn try_mutate_exists<KeyArg, R, E, F>(key: KeyArg, f: F) -> Result<R, E>where
KeyArg: EncodeLike<K>,
F: FnOnce(&mut Option<V>) -> 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
.
fn take<KeyArg>(key: KeyArg) -> Self::Querywhere
KeyArg: EncodeLike<K>,
fn take<KeyArg>(key: KeyArg) -> Self::Querywhere
KeyArg: EncodeLike<K>,
Take the value under a key.
fn 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.
fn migrate_key<OldHasher, KeyArg>(key: KeyArg) -> Option<V>where
OldHasher: StorageHasher,
KeyArg: EncodeLike<K>,
fn migrate_key<OldHasher, KeyArg>(key: KeyArg) -> Option<V>where
OldHasher: StorageHasher,
KeyArg: EncodeLike<K>,
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§
fn decode_len<KeyArg>(key: KeyArg) -> Option<usize>where
KeyArg: EncodeLike<K>,
V: StorageDecodeLength,
fn decode_len<KeyArg>(key: KeyArg) -> Option<usize>where
KeyArg: EncodeLike<K>,
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 completly
ignored by this function.
fn migrate_key_from_blake<KeyArg>(key: KeyArg) -> Option<V>where
KeyArg: EncodeLike<K>,
fn migrate_key_from_blake<KeyArg>(key: KeyArg) -> Option<V>where
KeyArg: EncodeLike<K>,
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.