Something get(fn something) 是什么:Option<u32>;在 Rust 中是什么意思?

What does Something get(fn something): Option<u32>; mean in Rust?

我克隆了 this template。 有这样一段代码:

decl_storage! {
    trait Store for Module<T: Trait> as TemplateModule {
        Something get(fn something): Option<u32>;
    }
}

Something get(fn something): Option<u32>;是什么意思? 特别是get(fn something)之前的Something是什么?

显然此宏接受自定义语法,如 https://substrate.dev/rustdocs/v2.0.0-rc5/frame_support/macro.decl_storage.html 中所述:

Basic storage can be extended as such:

#vis #name get(fn #getter) config(#field_name) build(#closure): #type = #default;

  • #vis: Set the visibility of the structure. pub or nothing.
  • #name: Name of the storage item, used as a prefix in storage.
  • [optional] get(fn #getter): Implements the function #getter to Module.
  • [optional] config(#field_name): field_name is optional if get is set. Will include the item in GenesisConfig.
  • [optional] build(#closure): Closure called with storage overlays.
  • #type: Storage type.
  • [optional] #default: Value returned when none.

所以在你的Something中是存储项目的名称,用作存储中的前缀。