Trait frame_support::storage::StorageDoubleMap
source · pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
type Query;
Show 21 methods
// Required methods
fn hashed_key_for<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Vec<u8> ⓘ
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn contains_key<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> bool
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Query
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn try_get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Result<V, ()>
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn set<KArg1: EncodeLike<K1>, KArg2: EncodeLike<K2>>(
k1: KArg1,
k2: KArg2,
query: Self::Query,
);
fn take<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Query
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn swap<XKArg1, XKArg2, YKArg1, YKArg2>(
x_k1: XKArg1,
x_k2: XKArg2,
y_k1: YKArg1,
y_k2: YKArg2,
)
where XKArg1: EncodeLike<K1>,
XKArg2: EncodeLike<K2>,
YKArg1: EncodeLike<K1>,
YKArg2: EncodeLike<K2>;
fn insert<KArg1, KArg2, VArg>(k1: KArg1, k2: KArg2, val: VArg)
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
VArg: EncodeLike<V>;
fn remove<KArg1, KArg2>(k1: KArg1, k2: KArg2)
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>;
fn remove_prefix<KArg1>(k1: KArg1, limit: Option<u32>) -> KillStorageResult
where KArg1: ?Sized + EncodeLike<K1>;
fn clear_prefix<KArg1>(
k1: KArg1,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> MultiRemovalResults
where KArg1: ?Sized + EncodeLike<K1>;
fn contains_prefix<KArg1>(k1: KArg1) -> bool
where KArg1: EncodeLike<K1>;
fn iter_prefix_values<KArg1>(k1: KArg1) -> PrefixIterator<V> ⓘ
where KArg1: ?Sized + EncodeLike<K1>;
fn mutate<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
F: FnOnce(&mut Self::Query) -> R;
fn try_mutate<KArg1, KArg2, R, E, F>(
k1: KArg1,
k2: KArg2,
f: F,
) -> Result<R, E>
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
F: FnOnce(&mut Self::Query) -> Result<R, E>;
fn mutate_exists<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
F: FnOnce(&mut Option<V>) -> R;
fn try_mutate_exists<KArg1, KArg2, R, E, F>(
k1: KArg1,
k2: KArg2,
f: F,
) -> Result<R, E>
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
F: FnOnce(&mut Option<V>) -> Result<R, E>;
fn append<Item, EncodeLikeItem, KArg1, KArg2>(
k1: KArg1,
k2: KArg2,
item: EncodeLikeItem,
)
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>;
fn migrate_keys<OldHasher1: StorageHasher, OldHasher2: StorageHasher, KeyArg1: EncodeLike<K1>, KeyArg2: EncodeLike<K2>>(
key1: KeyArg1,
key2: KeyArg2,
) -> Option<V>;
// Provided methods
fn decode_len<KArg1, KArg2>(key1: KArg1, key2: KArg2) -> Option<usize>
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
V: StorageDecodeLength { ... }
fn decode_non_dedup_len<KArg1, KArg2>(
key1: KArg1,
key2: KArg2,
) -> Option<usize>
where KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
V: StorageDecodeNonDedupLength { ... }
}
Expand description
An implementation of a map with a two keys.
Details on implementation can be found at [generator::StorageDoubleMap
].
Required Associated Types§
Required Methods§
sourcefn hashed_key_for<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Vec<u8> ⓘwhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn hashed_key_for<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Vec<u8> ⓘwhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Get the storage key used to fetch a value corresponding to a specific key.
sourcefn contains_key<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> boolwhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn contains_key<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> boolwhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Does the value (explicitly) exist in storage?
sourcefn get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Querywhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Querywhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Load the value associated with the given key from the double map.
sourcefn try_get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Result<V, ()>where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn try_get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Result<V, ()>where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Try to get the value for the given key from the double map.
Returns Ok
if it exists, Err
if not.
sourcefn set<KArg1: EncodeLike<K1>, KArg2: EncodeLike<K2>>(
k1: KArg1,
k2: KArg2,
query: Self::Query,
)
fn set<KArg1: EncodeLike<K1>, KArg2: EncodeLike<K2>>( k1: KArg1, k2: KArg2, query: Self::Query, )
Store or remove the value to be associated with key
so that get
returns the query
.
sourcefn take<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Querywhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn take<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Querywhere
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Take a value from storage, removing it afterwards.
sourcefn swap<XKArg1, XKArg2, YKArg1, YKArg2>(
x_k1: XKArg1,
x_k2: XKArg2,
y_k1: YKArg1,
y_k2: YKArg2,
)where
XKArg1: EncodeLike<K1>,
XKArg2: EncodeLike<K2>,
YKArg1: EncodeLike<K1>,
YKArg2: EncodeLike<K2>,
fn swap<XKArg1, XKArg2, YKArg1, YKArg2>(
x_k1: XKArg1,
x_k2: XKArg2,
y_k1: YKArg1,
y_k2: YKArg2,
)where
XKArg1: EncodeLike<K1>,
XKArg2: EncodeLike<K2>,
YKArg1: EncodeLike<K1>,
YKArg2: EncodeLike<K2>,
Swap the values of two key-pairs.
sourcefn insert<KArg1, KArg2, VArg>(k1: KArg1, k2: KArg2, val: VArg)
fn insert<KArg1, KArg2, VArg>(k1: KArg1, k2: KArg2, val: VArg)
Store a value to be associated with the given keys from the double map.
sourcefn remove<KArg1, KArg2>(k1: KArg1, k2: KArg2)where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
fn remove<KArg1, KArg2>(k1: KArg1, k2: KArg2)where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Remove the value under the given keys.
sourcefn remove_prefix<KArg1>(k1: KArg1, limit: Option<u32>) -> KillStorageResultwhere
KArg1: ?Sized + EncodeLike<K1>,
👎Deprecated: Use clear_prefix
instead
fn remove_prefix<KArg1>(k1: KArg1, limit: Option<u32>) -> KillStorageResultwhere
KArg1: ?Sized + EncodeLike<K1>,
clear_prefix
insteadRemove all values under the first key k1
in the overlay and up to limit
in the
backend.
All values in the client overlay will be deleted, if there is some limit
then up to
limit
values are deleted from the client backend, if limit
is none then all values in
the client backend are deleted.
§Note
Calling this multiple times per block with a limit
set leads always to the same keys being
removed and the same result being returned. This happens because the keys to delete in the
overlay are not taken into account when deleting keys in the backend.
sourcefn clear_prefix<KArg1>(
k1: KArg1,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> MultiRemovalResultswhere
KArg1: ?Sized + EncodeLike<K1>,
fn clear_prefix<KArg1>(
k1: KArg1,
limit: u32,
maybe_cursor: Option<&[u8]>,
) -> MultiRemovalResultswhere
KArg1: ?Sized + EncodeLike<K1>,
Remove all values under the first key k1
in the overlay and up to maybe_limit
in the
backend.
All values in the client overlay will be deleted, if maybe_limit
is Some
then up to
that number of values are deleted from the client backend, otherwise all values in the
client backend are deleted.
§Cursors
The maybe_cursor
parameter should be None
for the first call to initial removal.
If the resultant maybe_cursor
is Some
, then another call is required to complete the
removal operation. This value must be passed in as the subsequent call’s maybe_cursor
parameter. If the resultant maybe_cursor
is None
, then the operation is complete and no
items remain in storage provided that no items were added between the first calls and the
final call.
sourcefn contains_prefix<KArg1>(k1: KArg1) -> boolwhere
KArg1: EncodeLike<K1>,
fn contains_prefix<KArg1>(k1: KArg1) -> boolwhere
KArg1: EncodeLike<K1>,
Does any value under the first key k1
(explicitly) exist in storage?
Might have unexpected behaviour with empty keys, e.g. []
.
sourcefn iter_prefix_values<KArg1>(k1: KArg1) -> PrefixIterator<V> ⓘwhere
KArg1: ?Sized + EncodeLike<K1>,
fn iter_prefix_values<KArg1>(k1: KArg1) -> PrefixIterator<V> ⓘwhere
KArg1: ?Sized + EncodeLike<K1>,
Iterate over values that share the first key.
sourcefn mutate<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
fn mutate<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
Mutate the value under the given keys.
sourcefn try_mutate<KArg1, KArg2, R, E, F>(k1: KArg1, k2: KArg2, f: F) -> Result<R, E>
fn try_mutate<KArg1, KArg2, R, E, F>(k1: KArg1, k2: KArg2, f: F) -> Result<R, E>
Mutate the value under the given keys when the closure returns Ok
.
sourcefn mutate_exists<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
fn mutate_exists<KArg1, KArg2, R, F>(k1: KArg1, k2: KArg2, f: F) -> R
Mutate the value under the given keys. Deletes the item if mutated to a None
.
sourcefn try_mutate_exists<KArg1, KArg2, R, E, F>(
k1: KArg1,
k2: KArg2,
f: F,
) -> Result<R, E>
fn try_mutate_exists<KArg1, KArg2, R, E, F>( k1: KArg1, k2: KArg2, 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 append<Item, EncodeLikeItem, KArg1, KArg2>(
k1: KArg1,
k2: KArg2,
item: EncodeLikeItem,
)where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>,
fn append<Item, EncodeLikeItem, KArg1, KArg2>(
k1: KArg1,
k2: KArg2,
item: EncodeLikeItem,
)where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
Item: Encode,
EncodeLikeItem: EncodeLike<Item>,
V: StorageAppend<Item>,
Append the given item to the value in the storage.
V
is required to implement StorageAppend
.
§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_keys<OldHasher1: StorageHasher, OldHasher2: StorageHasher, KeyArg1: EncodeLike<K1>, KeyArg2: EncodeLike<K2>>(
key1: KeyArg1,
key2: KeyArg2,
) -> Option<V>
fn migrate_keys<OldHasher1: StorageHasher, OldHasher2: StorageHasher, KeyArg1: EncodeLike<K1>, KeyArg2: EncodeLike<K2>>( key1: KeyArg1, key2: KeyArg2, ) -> Option<V>
Migrate an item with the given key1
and key2
from defunct OldHasher1
and
OldHasher2
to the current hashers.
If the key doesn’t exist, then it’s a no-op. If it does, then it returns its value.
Provided Methods§
sourcefn decode_len<KArg1, KArg2>(key1: KArg1, key2: KArg2) -> Option<usize>
fn decode_len<KArg1, KArg2>(key1: KArg1, key2: KArg2) -> Option<usize>
Read the length of the storage value without decoding the entire value under the
given key1
and key2
.
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<KArg1, KArg2>(key1: KArg1, key2: KArg2) -> Option<usize>
fn decode_non_dedup_len<KArg1, KArg2>(key1: KArg1, key2: KArg2) -> Option<usize>
Read the length of the storage value without decoding the entire value under the
given key1
and key2
.
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 that get()
does not return a value. The default value is completely
ignored by this function.