Search code examples
dictionaryrustsubstrate

Rust Map Syntax Explanation Needed


recently started learning Rust and I am having some problems with syntax. Can anyone explain to me this line:

// Stores all the kitties, key is the kitty id / index

pub Kitties get(fn kitties): map hasher(blake2_128_concat) u32 => Option<Kitty>;

So we're creating here public Kitties(variable) that accepts some function. Kitties is of a type map hasher(blake2_128_concat) u32 which returns Option

map hasher? Also couldn't find hasher in documentation.


Solution

  • Based on the link you posted in the comments, the code snippet is part of a larger snippet that looks something like

    decl_storage! {
        trait Store for Module<T: Trait> as SimpleMap {
            SimpleMap get(fn simple_map): map hasher(blake2_128_concat) T::AccountId => u32;
        }
    }
    

    The decl_storage! call is a macro (macro calls are always ended in an exclamation point, like vec! or println!), which in essence means it can do whatever it wants with the stuff that follows it. In particular, the things inside the outer braces needn't be valid Rust, as decl_storage! can transform the contents freely.

    My guess (at a quick Google search) is that decl_storage! refers to this macro, so you'll have to refer to its documentation to see what it expects.