From ad8f391494e346c4b035969460ae7206ae880862 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 22 Apr 2021 22:53:49 -0700 Subject: [PATCH] Rename KeyGenerator::Arg to KeyGenerator::KArg --- frame/support/src/storage/generator/nmap.rs | 30 ++++++++++----------- frame/support/src/storage/mod.rs | 30 ++++++++++----------- frame/support/src/storage/types/key.rs | 12 ++++----- frame/support/src/storage/types/nmap.rs | 30 ++++++++++----------- 4 files changed, 51 insertions(+), 51 deletions(-) diff --git a/frame/support/src/storage/generator/nmap.rs b/frame/support/src/storage/generator/nmap.rs index 375a321f483d9..41438b077f475 100755 --- a/frame/support/src/storage/generator/nmap.rs +++ b/frame/support/src/storage/generator/nmap.rs @@ -97,7 +97,7 @@ pub trait StorageNMap { fn storage_n_map_final_key(key: KArg) -> Vec where KG: KeyGenerator, - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, { let module_prefix_hashed = Twox128::hash(Self::module_prefix()); let storage_prefix_hashed = Twox128::hash(Self::storage_prefix()); @@ -123,23 +123,23 @@ where { type Query = G::Query; - fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec { + fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec { Self::storage_n_map_final_key::(key) } - fn contains_key + TupleToEncodedIter>(key: KArg) -> bool { + fn contains_key + TupleToEncodedIter>(key: KArg) -> bool { unhashed::exists(&Self::storage_n_map_final_key::(key)) } - fn get + TupleToEncodedIter>(key: KArg) -> Self::Query { + fn get + TupleToEncodedIter>(key: KArg) -> Self::Query { G::from_optional_value_to_query(unhashed::get(&Self::storage_n_map_final_key::(key))) } - fn try_get + TupleToEncodedIter>(key: KArg) -> Result { + fn try_get + TupleToEncodedIter>(key: KArg) -> Result { unhashed::get(&Self::storage_n_map_final_key::(key)).ok_or(()) } - fn take + TupleToEncodedIter>(key: KArg) -> Self::Query { + fn take + TupleToEncodedIter>(key: KArg) -> Self::Query { let final_key = Self::storage_n_map_final_key::(key); let value = unhashed::take(&final_key); @@ -149,8 +149,8 @@ where fn swap(key1: KArg1, key2: KArg2) where KOther: KeyGenerator, - KArg1: EncodeLike + TupleToEncodedIter, - KArg2: EncodeLike + TupleToEncodedIter, + KArg1: EncodeLike + TupleToEncodedIter, + KArg2: EncodeLike + TupleToEncodedIter, { let final_x_key = Self::storage_n_map_final_key::(key1); let final_y_key = Self::storage_n_map_final_key::(key2); @@ -168,11 +168,11 @@ where } } - fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg) { + fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg) { unhashed::put(&Self::storage_n_map_final_key::(key), &val.borrow()); } - fn remove + TupleToEncodedIter>(key: KArg) { + fn remove + TupleToEncodedIter>(key: KArg) { unhashed::kill(&Self::storage_n_map_final_key::(key)); } @@ -193,14 +193,14 @@ where } } - fn mutate + TupleToEncodedIter, R, F: FnOnce(&mut Self::Query) -> R>( + fn mutate + TupleToEncodedIter, R, F: FnOnce(&mut Self::Query) -> R>( key: KArg, f: F, ) -> R { Self::try_mutate(key, |v| Ok::(f(v))).expect("`Never` can not be constructed; qed") } - fn try_mutate + TupleToEncodedIter, R, E, F: FnOnce(&mut Self::Query) -> Result>( + fn try_mutate + TupleToEncodedIter, R, E, F: FnOnce(&mut Self::Query) -> Result>( key: KArg, f: F, ) -> Result { @@ -217,14 +217,14 @@ where ret } - fn mutate_exists + TupleToEncodedIter, R, F: FnOnce(&mut Option) -> R>( + fn mutate_exists + TupleToEncodedIter, R, F: FnOnce(&mut Option) -> R>( key: KArg, f: F, ) -> R { Self::try_mutate_exists(key, |v| Ok::(f(v))).expect("`Never` can not be constructed; qed") } - fn try_mutate_exists + TupleToEncodedIter, R, E, F: FnOnce(&mut Option) -> Result>( + fn try_mutate_exists + TupleToEncodedIter, R, E, F: FnOnce(&mut Option) -> Result>( key: KArg, f: F, ) -> Result { @@ -243,7 +243,7 @@ where fn append(key: KArg, item: EncodeLikeItem) where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, Item: Encode, EncodeLikeItem: EncodeLike, V: StorageAppend diff --git a/frame/support/src/storage/mod.rs b/frame/support/src/storage/mod.rs index a8717ca0f6b5a..8ab17a4cd4ec7 100644 --- a/frame/support/src/storage/mod.rs +++ b/frame/support/src/storage/mod.rs @@ -552,31 +552,31 @@ pub trait StorageNMap { type Query; /// Get the storage key used to fetch a value corresponding to a specific key. - fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec; + fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec; /// Does the value (explicitly) exist in storage? - fn contains_key + TupleToEncodedIter>(key: KArg) -> bool; + fn contains_key + TupleToEncodedIter>(key: KArg) -> bool; /// Load the value associated with the given key from the map. - fn get + TupleToEncodedIter>(key: KArg) -> Self::Query; + fn get + TupleToEncodedIter>(key: KArg) -> Self::Query; /// Try to get the value for the given key from the map. /// /// Returns `Ok` if it exists, `Err` if not. - fn try_get + TupleToEncodedIter>(key: KArg) -> Result; + fn try_get + TupleToEncodedIter>(key: KArg) -> Result; /// Swap the values of two keys. fn swap(key1: KArg1, key2: KArg2) where KOther: KeyGenerator, - KArg1: EncodeLike + TupleToEncodedIter, - KArg2: EncodeLike + TupleToEncodedIter; + KArg1: EncodeLike + TupleToEncodedIter, + KArg2: EncodeLike + TupleToEncodedIter; /// Store a value to be associated with the given key from the map. - fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg); + fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg); /// Remove the value under a key. - fn remove + TupleToEncodedIter>(key: KArg); + fn remove + TupleToEncodedIter>(key: KArg); /// Remove all values under the partial prefix key. fn remove_prefix(partial_key: KP) where K: HasKeyPrefix; @@ -585,10 +585,10 @@ pub trait StorageNMap { fn iter_prefix_values(partial_key: KP) -> PrefixIterator where K: HasKeyPrefix; /// Mutate the value under a key. - fn mutate + TupleToEncodedIter, R, F: FnOnce(&mut Self::Query) -> R>(key: KArg, f: F) -> R; + fn mutate + TupleToEncodedIter, R, F: FnOnce(&mut Self::Query) -> R>(key: KArg, f: F) -> R; /// Mutate the item, only if an `Ok` value is returned. - fn try_mutate + TupleToEncodedIter, R, E, F: FnOnce(&mut Self::Query) -> Result>( + fn try_mutate + TupleToEncodedIter, R, E, F: FnOnce(&mut Self::Query) -> Result>( key: KArg, f: F, ) -> Result; @@ -596,16 +596,16 @@ pub trait StorageNMap { /// Mutate the value under a key. /// /// Deletes the item if mutated to a `None`. - fn mutate_exists + TupleToEncodedIter, R, F: FnOnce(&mut Option) -> R>(key: KArg, f: F) -> R; + fn mutate_exists + TupleToEncodedIter, R, F: FnOnce(&mut Option) -> R>(key: KArg, f: F) -> R; /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. - fn try_mutate_exists + TupleToEncodedIter, R, E, F: FnOnce(&mut Option) -> Result>( + fn try_mutate_exists + TupleToEncodedIter, R, E, F: FnOnce(&mut Option) -> Result>( key: KArg, f: F, ) -> Result; /// Take the value under a key. - fn take + TupleToEncodedIter>(key: KArg) -> Self::Query; + fn take + TupleToEncodedIter>(key: KArg) -> Self::Query; /// Append the given items to the value in the storage. /// @@ -618,7 +618,7 @@ pub trait StorageNMap { /// on overwrite. fn append(key: KArg, item: EncodeLikeItem) where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, Item: Encode, EncodeLikeItem: EncodeLike, V: StorageAppend; @@ -635,7 +635,7 @@ pub trait StorageNMap { /// /// `None` does not mean that `get()` does not return a value. The default value is completly /// ignored by this function. - fn decode_len + TupleToEncodedIter>(key: KArg) -> Option + fn decode_len + TupleToEncodedIter>(key: KArg) -> Option where V: StorageDecodeLength, { diff --git a/frame/support/src/storage/types/key.rs b/frame/support/src/storage/types/key.rs index fa3dbe0ffbd11..012d5c75888a7 100755 --- a/frame/support/src/storage/types/key.rs +++ b/frame/support/src/storage/types/key.rs @@ -38,17 +38,17 @@ pub struct Key( /// A trait that contains the current key as an associated type. pub trait KeyGenerator { type Key: EncodeLike; - type Arg: Encode; + type KArg: Encode; - fn final_key + TupleToEncodedIter>(key: KArg) -> Vec; + fn final_key + TupleToEncodedIter>(key: KArg) -> Vec; fn final_hash(encoded: &[u8]) -> Vec; } impl KeyGenerator for Key { type Key = K; - type Arg = (K,); + type KArg = (K,); - fn final_key + TupleToEncodedIter>(key: KArg) -> Vec { + fn final_key + TupleToEncodedIter>(key: KArg) -> Vec { H::hash(&key.to_encoded_iter().next().expect("should have at least one element!")).as_ref().to_vec() } @@ -60,9 +60,9 @@ impl KeyGenerator for Key { #[impl_trait_for_tuples::impl_for_tuples(2, 18)] impl KeyGenerator for Tuple { for_tuples!( type Key = ( #(Tuple::Key),* ); ); - for_tuples!( type Arg = ( #(Tuple::Key),* ); ); + for_tuples!( type KArg = ( #(Tuple::Key),* ); ); - fn final_key + TupleToEncodedIter>(key: KArg) -> Vec { + fn final_key + TupleToEncodedIter>(key: KArg) -> Vec { let mut final_key = Vec::new(); let mut iter = key.to_encoded_iter(); for_tuples!( diff --git a/frame/support/src/storage/types/nmap.rs b/frame/support/src/storage/types/nmap.rs index ea8d5292ded79..7141899fb5b1c 100755 --- a/frame/support/src/storage/types/nmap.rs +++ b/frame/support/src/storage/types/nmap.rs @@ -103,29 +103,29 @@ where OnEmpty: crate::traits::Get + 'static, { /// Get the storage key used to fetch a value corresponding to a specific key. - pub fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec { + pub fn hashed_key_for + TupleToEncodedIter>(key: KArg) -> Vec { >::hashed_key_for(key) } /// Does the value (explicitly) exist in storage? - pub fn contains_key + TupleToEncodedIter>(key: KArg) -> bool { + pub fn contains_key + TupleToEncodedIter>(key: KArg) -> bool { >::contains_key(key) } /// Load the value associated with the given key from the map. - pub fn get + TupleToEncodedIter>(key: KArg) -> QueryKind::Query { + pub fn get + TupleToEncodedIter>(key: KArg) -> QueryKind::Query { >::get(key) } /// Try to get the value for the given key from the map. /// /// Returns `Ok` if it exists, `Err` if not. - pub fn try_get + TupleToEncodedIter>(key: KArg) -> Result { + pub fn try_get + TupleToEncodedIter>(key: KArg) -> Result { >::try_get(key) } /// Take a value from storage, removing it afterwards. - pub fn take + TupleToEncodedIter>(key: KArg) -> QueryKind::Query { + pub fn take + TupleToEncodedIter>(key: KArg) -> QueryKind::Query { >::take(key) } @@ -133,19 +133,19 @@ where pub fn swap(key1: KArg1, key2: KArg2) where KOther: KeyGenerator, - KArg1: EncodeLike + TupleToEncodedIter, - KArg2: EncodeLike + TupleToEncodedIter, + KArg1: EncodeLike + TupleToEncodedIter, + KArg2: EncodeLike + TupleToEncodedIter, { >::swap::(key1, key2) } /// Store a value to be associated with the given keys from the map. - pub fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg) { + pub fn insert + TupleToEncodedIter, VArg: EncodeLike>(key: KArg, val: VArg) { >::insert(key, val) } /// Remove the value under the given keys. - pub fn remove + TupleToEncodedIter>(key: KArg) { + pub fn remove + TupleToEncodedIter>(key: KArg) { >::remove(key) } @@ -165,7 +165,7 @@ where /// Mutate the value under the given keys. pub fn mutate(key: KArg, f: F) -> R where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, F: FnOnce(&mut QueryKind::Query) -> R, { >::mutate(key, f) @@ -174,7 +174,7 @@ where /// Mutate the value under the given keys when the closure returns `Ok`. pub fn try_mutate(key: KArg, f: F) -> Result where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, F: FnOnce(&mut QueryKind::Query) -> Result, { >::try_mutate(key, f) @@ -183,7 +183,7 @@ where /// Mutate the value under the given keys. Deletes the item if mutated to a `None`. pub fn mutate_exists(key: KArg, f: F) -> R where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, F: FnOnce(&mut Option) -> R, { >::mutate_exists(key, f) @@ -192,7 +192,7 @@ where /// Mutate the item, only if an `Ok` value is returned. Deletes the item if mutated to a `None`. pub fn try_mutate_exists(key: KArg, f: F) -> Result where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, F: FnOnce(&mut Option) -> Result, { >::try_mutate_exists(key, f) @@ -209,7 +209,7 @@ where /// on overwrite. pub fn append(key: KArg, item: EncodeLikeItem) where - KArg: EncodeLike + TupleToEncodedIter, + KArg: EncodeLike + TupleToEncodedIter, Item: Encode, EncodeLikeItem: EncodeLike, Value: StorageAppend @@ -229,7 +229,7 @@ where /// /// `None` does not mean that `get()` does not return a value. The default value is completly /// ignored by this function. - pub fn decode_len + TupleToEncodedIter>(key: KArg) -> Option + pub fn decode_len + TupleToEncodedIter>(key: KArg) -> Option where Value: StorageDecodeLength, {