fn key_hash<K: Encode>(key: &K, hasher: &StorageHasher) -> Vec<u8> {
    let encoded_key = key.encode();
    match hasher {
        StorageHasher::Identity => encoded_key.to_vec(),
        StorageHasher::Blake2_128 => sp_core::blake2_128(&encoded_key).to_vec(),
        StorageHasher::Blake2_128Concat => {
            // copied from substrate Blake2_128Concat::hash since StorageHasher is not public
            let x: &[u8] = encoded_key.as_slice();
            sp_core::blake2_128(x)
                .iter()
                .chain(x.iter())
                .cloned()
                .collect::<Vec<_>>()
        }
        StorageHasher::Blake2_256 => sp_core::blake2_256(&encoded_key).to_vec(),
        StorageHasher::Twox128 => sp_core::twox_128(&encoded_key).to_vec(),
        StorageHasher::Twox256 => sp_core::twox_256(&encoded_key).to_vec(),
        StorageHasher::Twox64Concat => sp_core::twox_64(&encoded_key).to_vec(),
    }
}
/// generates the key's hash depending on the StorageHasher selected
generates the key's hash depending on the StorageHasher selected
generates the key ' s hash depending on the StorageHasher selected
fn key_hash<K: Encode>(key: &K, hasher: &StorageHasher) -> Vec<u8> {
    let encoded_key = key.encode();
    match hasher {
        StorageHasher::Identity => encoded_key.to_vec(),
        StorageHasher::Blake2_128 => sp_core::blake2_128(&encoded_key).to_vec(),
        StorageHasher::Blake2_128Concat => {
            // copied from substrate Blake2_128Concat::hash since StorageHasher is not public
            let x: &[u8] = encoded_key.as_slice();
            sp_core::blake2_128(x)
                .iter()
                .chain(x.iter())
                .cloned()
                .collect::<Vec<_>>()
        }
        StorageHasher::Blake2_256 => sp_core::blake2_256(&encoded_key).to_vec(),
        StorageHasher::Twox128 => sp_core::twox_128(&encoded_key).to_vec(),
        StorageHasher::Twox256 => sp_core::twox_256(&encoded_key).to_vec(),
        StorageHasher::Twox64Concat => sp_core::twox_64(&encoded_key).to_vec(),
    }
}
fn key_hash < K : Encode > ( key : & K , hasher : & StorageHasher ) -> Vec < u8 > { let encoded_key = key . encode ( ) ; match hasher { StorageHasher :: Identity => encoded_key . to_vec ( ) , StorageHasher :: Blake2_128 => sp_core :: blake2_128 ( & encoded_key ) . to_vec ( ) , StorageHasher :: Blake2_128Concat => { // copied from substrate Blake2_128Concat::hash since StorageHasher is not public let x : & [ u8 ] = encoded_key . as_slice ( ) ; sp_core :: blake2_128 ( x ) . iter ( ) . chain ( x . iter ( ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) } StorageHasher :: Blake2_256 => sp_core :: blake2_256 ( & encoded_key ) . to_vec ( ) , StorageHasher :: Twox128 => sp_core :: twox_128 ( & encoded_key ) . to_vec ( ) , StorageHasher :: Twox256 => sp_core :: twox_256 ( & encoded_key ) . to_vec ( ) , StorageHasher :: Twox64Concat => sp_core :: twox_64 ( & encoded_key ) . to_vec ( ) , } }
generates the key's hash depending on the StorageHasher selected
generates the key ' s hash depending on the StorageHasher selected
key
&K
hasher
&StorageHasher
key
&K
hasher
&StorageHasher