mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 23:31:07 +00:00
Explicitly declare decl_storage! getters as functions (#3870)
* parse decl_storage getters with fn keyword * test for get in decl_storage * update all decl_storage! getters * bump version * adjust missed doc line
This commit is contained in:
committed by
Bastian Köcher
parent
1111d79ac1
commit
5d5e71028e
@@ -33,7 +33,7 @@ use proc_macro::TokenStream;
|
||||
/// ```nocompile
|
||||
/// decl_storage! {
|
||||
/// trait Store for Module<T: Trait> as Example {
|
||||
/// Foo get(foo) config(): u32=12;
|
||||
/// Foo get(fn foo) config(): u32=12;
|
||||
/// Bar: map u32 => u32;
|
||||
/// pub Zed build(|config| vec![(0, 0)]): linked_map u32 => u32;
|
||||
/// }
|
||||
@@ -120,11 +120,11 @@ use proc_macro::TokenStream;
|
||||
///
|
||||
/// Basic storage can be extended as such:
|
||||
///
|
||||
/// `#vis #name get(#getter) config(#field_name) build(#closure): #type = #default;`
|
||||
/// `#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(#getter)`: Implements the function #getter to `Module`.
|
||||
/// * [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.
|
||||
|
||||
@@ -113,11 +113,16 @@ struct DeclStorageLine {
|
||||
pub default_value: ext::Opt<DeclStorageDefault>,
|
||||
}
|
||||
|
||||
#[derive(Parse, ToTokens, Debug)]
|
||||
struct DeclStorageGetterBody {
|
||||
fn_keyword: Option<Token![fn]>,
|
||||
ident: Ident,
|
||||
}
|
||||
|
||||
#[derive(Parse, ToTokens, Debug)]
|
||||
struct DeclStorageGetter {
|
||||
pub getter_keyword: keyword::get,
|
||||
pub getfn: ext::Parens<Ident>,
|
||||
pub getfn: ext::Parens<DeclStorageGetterBody>,
|
||||
}
|
||||
|
||||
#[derive(Parse, ToTokens, Debug)]
|
||||
@@ -301,17 +306,17 @@ pub fn parse(input: syn::parse::ParseStream) -> syn::Result<super::DeclStorageDe
|
||||
let mut storage_lines = vec![];
|
||||
|
||||
for line in def.content.content.inner.into_iter() {
|
||||
let getter = line.getter.inner.map(|o| o.getfn.content);
|
||||
let getter = line.getter.inner.map(|o| o.getfn.content.ident);
|
||||
let config = if let Some(config) = line.config.inner {
|
||||
if let Some(ident) = config.expr.content {
|
||||
Some(ident)
|
||||
} else if let Some(ident) = getter.clone() {
|
||||
Some(ident)
|
||||
} else if let Some(ref ident) = getter {
|
||||
Some(ident.clone())
|
||||
} else {
|
||||
return Err(syn::Error::new(
|
||||
config.span(),
|
||||
"Invalid storage definiton, couldn't find config identifier: storage must either have a get \
|
||||
identifier `get(ident)` or a defined config identifier `config(ident)`"
|
||||
identifier `get(fn ident)` or a defined config identifier `config(ident)`"
|
||||
))
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user