mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 10:31:04 +00:00
Maps are appendable too (#2716)
* Maps are appendable too * Update srml/support/src/storage/hashed/generator.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Update srml/support/src/storage/mod.rs Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com> * Fix docs * Make Appendable public * Bump runtime version
This commit is contained in:
@@ -330,6 +330,25 @@ impl<K: Codec, V: Codec, U> StorageMap<K, V> for U where U: hashed::generator::S
|
||||
}
|
||||
}
|
||||
|
||||
/// A storage map with values that can be appended to.
|
||||
pub trait AppendableStorageMap<K: Codec, V: Codec>: StorageMap<K, V> {
|
||||
/// Append the given item to the value in the storage.
|
||||
///
|
||||
/// `T` is required to implement `codec::EncodeAppend`.
|
||||
fn append<KeyArg: Borrow<K>, I: Encode>(key: KeyArg, items: &[I]) -> Result<(), &'static str>
|
||||
where V: EncodeAppend<Item=I>;
|
||||
}
|
||||
|
||||
impl<K: Codec, V: Codec, U> AppendableStorageMap<K, V> for U
|
||||
where U: hashed::generator::AppendableStorageMap<K, V>
|
||||
{
|
||||
fn append<KeyArg: Borrow<K>, I: Encode>(key: KeyArg, items: &[I]) -> Result<(), &'static str>
|
||||
where V: EncodeAppend<Item=I>
|
||||
{
|
||||
U::append(key.borrow(), items, &mut RuntimeStorage)
|
||||
}
|
||||
}
|
||||
|
||||
/// A storage map that can be enumerated.
|
||||
///
|
||||
/// Primarily useful for off-chain computations.
|
||||
@@ -342,7 +361,9 @@ pub trait EnumerableStorageMap<K: Codec, V: Codec>: StorageMap<K, V> {
|
||||
fn enumerate() -> Box<dyn Iterator<Item = (K, V)>> where K: 'static, V: 'static;
|
||||
}
|
||||
|
||||
impl<K: Codec, V: Codec, U> EnumerableStorageMap<K, V> for U where U: hashed::generator::EnumerableStorageMap<K, V> {
|
||||
impl<K: Codec, V: Codec, U> EnumerableStorageMap<K, V> for U
|
||||
where U: hashed::generator::EnumerableStorageMap<K, V>
|
||||
{
|
||||
fn head() -> Option<K> {
|
||||
<U as hashed::generator::EnumerableStorageMap<K, V>>::head(&RuntimeStorage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user