gpt4 book ai didi

syntax - 什么东西会得到(fn something): Option; mean in Rust?

转载 作者:行者123 更新时间:2023-12-03 11:37:06 25 4
gpt4 key购买 nike

我克隆了this template
有这样的代码:

decl_storage! {
trait Store for Module<T: Trait> as TemplateModule {
Something get(fn something): Option<u32>;
}
}
Something get(fn something): Option<u32>;是什么意思?
特别是 Something之前的 get(fn 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中是存储项的名称,用作存储中的前缀。

关于syntax - 什么东西会得到(fn something): Option<u32>; mean in Rust?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63279496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com