In the tutorial of learning substrate, a storage map for stored items is defined as follows, in which the symbol =>
appears, but this specification is not in the standard syntax of rust. How to understand it?
MyMap get(my_map): map u8 => Vec<u8>;
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityIn the tutorial of learning substrate, a storage map for stored items is defined as follows, in which the symbol =>
appears, but this specification is not in the standard syntax of rust. How to understand it?
MyMap get(my_map): map u8 => Vec<u8>;
It's not standard Rust syntax because it makes use of the #[pallet::storage]
macro. Please have a look at the official documentation for the macro and the StorageMap type for more information.
In short,
#[pallet::storage]
#[pallet::getter(fn some_map)]
pub(super) type SomeMap<T: Config> = StorageMap<_, Blake2_128Concat, SomeKey, SomeValue, ValueQuery>;
sets up a StorageMap with name SomeMap
for SomeKey => SomeValue
with getter function some_map
using the Blake2_128Concat
hasher. ValueQuery
states that the resulting value lookup is not wrapped into an Option, which would be the case if you were using OptionQuery
(default implementation of the QueryKind generic).