mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 06:01:06 +00:00
More documentation improvements (#1972)
* Bring back public calls in `Module` documentation * Forward storage item documentation to storage structs
This commit is contained in:
committed by
thiolliere
parent
3149136367
commit
71c0d4d968
@@ -29,7 +29,7 @@ pub fn option_unwrap(is_option: bool) -> TokenStream2 {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Impls<'a> {
|
||||
pub(crate) struct Impls<'a, I: Iterator<Item=syn::Meta>> {
|
||||
pub scrate: &'a TokenStream2,
|
||||
pub visibility: &'a syn::Visibility,
|
||||
pub traitinstance: &'a syn::Ident,
|
||||
@@ -38,9 +38,10 @@ pub(crate) struct Impls<'a> {
|
||||
pub fielddefault: TokenStream2,
|
||||
pub prefix: String,
|
||||
pub name: &'a syn::Ident,
|
||||
pub attrs: I,
|
||||
}
|
||||
|
||||
impl<'a> Impls<'a> {
|
||||
impl<'a, I: Iterator<Item=syn::Meta>> Impls<'a, I> {
|
||||
pub fn simple_value(self) -> TokenStream2 {
|
||||
let Self {
|
||||
scrate,
|
||||
@@ -51,6 +52,7 @@ impl<'a> Impls<'a> {
|
||||
fielddefault,
|
||||
prefix,
|
||||
name,
|
||||
attrs,
|
||||
} = self;
|
||||
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
|
||||
let option_simple_1 = option_unwrap(is_option);
|
||||
@@ -70,7 +72,7 @@ impl<'a> Impls<'a> {
|
||||
|
||||
// generator for value
|
||||
quote!{
|
||||
|
||||
#( #[ #attrs ] )*
|
||||
#visibility struct #name<#traitinstance: #traittype>(#scrate::storage::generator::PhantomData<#traitinstance>);
|
||||
|
||||
impl<#traitinstance: #traittype> #scrate::storage::generator::StorageValue<#typ> for #name<#traitinstance> {
|
||||
@@ -102,7 +104,6 @@ impl<'a> Impls<'a> {
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +117,7 @@ impl<'a> Impls<'a> {
|
||||
fielddefault,
|
||||
prefix,
|
||||
name,
|
||||
attrs,
|
||||
} = self;
|
||||
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
|
||||
let option_simple_1 = option_unwrap(is_option);
|
||||
@@ -134,6 +136,7 @@ impl<'a> Impls<'a> {
|
||||
};
|
||||
// generator for map
|
||||
quote!{
|
||||
#( #[ #attrs ] )*
|
||||
#visibility struct #name<#traitinstance: #traittype>(#scrate::storage::generator::PhantomData<#traitinstance>);
|
||||
|
||||
impl<#traitinstance: #traittype> #scrate::storage::generator::StorageMap<#kty, #typ> for #name<#traitinstance> {
|
||||
@@ -186,12 +189,12 @@ impl<'a> Impls<'a> {
|
||||
fielddefault,
|
||||
prefix,
|
||||
name,
|
||||
attrs,
|
||||
} = self;
|
||||
let DeclStorageTypeInfos { typ, value_type, is_option, .. } = type_infos;
|
||||
let option_simple_1 = option_unwrap(is_option);
|
||||
// make sure to use different prefix for head and elements.
|
||||
let head_key = format!("head of {}", prefix);
|
||||
let prefix = format!("{}", prefix);
|
||||
let name_lowercase = name.to_string().to_lowercase();
|
||||
let inner_module = syn::Ident::new(&format!("__linked_map_details_for_{}_do_not_use", name_lowercase), name.span());
|
||||
let linkage = syn::Ident::new(&format!("__LinkageFor{}DoNotUse", name), name.span());
|
||||
@@ -300,6 +303,7 @@ impl<'a> Impls<'a> {
|
||||
};
|
||||
|
||||
let structure = quote! {
|
||||
#( #[ #attrs ] )*
|
||||
#visibility struct #name<#traitinstance: #traittype>(#phantom_data<#traitinstance>);
|
||||
|
||||
impl<#traitinstance: #traittype> self::#inner_module::Utils<#traitinstance> for #name<#traitinstance> {
|
||||
|
||||
@@ -434,6 +434,7 @@ fn decl_storage_items(
|
||||
let mut impls = TokenStream2::new();
|
||||
for sline in storage_lines.inner.iter() {
|
||||
let DeclStorageLine {
|
||||
attrs,
|
||||
name,
|
||||
storage_type,
|
||||
default_value,
|
||||
@@ -443,6 +444,9 @@ fn decl_storage_items(
|
||||
|
||||
let type_infos = get_type_infos(storage_type);
|
||||
let kind = type_infos.kind.clone();
|
||||
// Propagate doc attributes.
|
||||
let attrs = attrs.inner.iter().filter_map(|a| a.parse_meta().ok()).filter(|m| m.name() == "doc");
|
||||
|
||||
let i = impls::Impls {
|
||||
scrate,
|
||||
visibility,
|
||||
@@ -453,6 +457,7 @@ fn decl_storage_items(
|
||||
.unwrap_or_else(|| quote!{ Default::default() }),
|
||||
prefix: format!("{} {}", cratename, name),
|
||||
name,
|
||||
attrs,
|
||||
};
|
||||
|
||||
let implementation = match kind {
|
||||
|
||||
@@ -66,7 +66,7 @@ pub fn generate_crate_access(unique_id: &str, def_crate: &str) -> TokenStream {
|
||||
} else {
|
||||
let mod_name = generate_hidden_includes_mod_name(unique_id);
|
||||
quote::quote!( self::#mod_name::hidden_include )
|
||||
}.into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates the hidden includes that are required to make the macro independent from its scope.
|
||||
@@ -92,7 +92,7 @@ pub fn generate_hidden_includes(unique_id: &str, def_crate: &str) -> TokenStream
|
||||
}
|
||||
}
|
||||
|
||||
}.into()
|
||||
}
|
||||
}
|
||||
|
||||
// fn to remove white spaces arount string types
|
||||
|
||||
@@ -484,10 +484,11 @@ macro_rules! decl_module {
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$origin_ty:ty;
|
||||
root;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn $name:ident ( root $(, $param:ident : $param_ty:ty )* ) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
#[doc(hidden)]
|
||||
$(#[doc = $doc_attr])*
|
||||
$vis fn $name($( $param: $param_ty ),* ) -> $crate::dispatch::Result {
|
||||
{ $( $impl )* }
|
||||
Ok(())
|
||||
@@ -499,12 +500,13 @@ macro_rules! decl_module {
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$origin_ty:ty;
|
||||
root;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn $name:ident (
|
||||
root $(, $param:ident : $param_ty:ty )*
|
||||
) -> $result:ty { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
#[doc(hidden)]
|
||||
$(#[doc = $doc_attr])*
|
||||
$vis fn $name($( $param: $param_ty ),* ) -> $result {
|
||||
$( $impl )*
|
||||
}
|
||||
@@ -515,12 +517,13 @@ macro_rules! decl_module {
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$origin_ty:ty;
|
||||
$ignore:ident;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn $name:ident (
|
||||
$origin:ident $(, $param:ident : $param_ty:ty )*
|
||||
) { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
#[doc(hidden)]
|
||||
$(#[doc = $doc_attr])*
|
||||
$vis fn $name(
|
||||
$origin: $origin_ty $(, $param: $param_ty )*
|
||||
) -> $crate::dispatch::Result {
|
||||
@@ -534,11 +537,13 @@ macro_rules! decl_module {
|
||||
$module:ident<$trait_instance:ident: $trait_name:ident>;
|
||||
$origin_ty:ty;
|
||||
$ignore:ident;
|
||||
$(#[doc = $doc_attr:tt])*
|
||||
$vis:vis fn $name:ident (
|
||||
$origin:ident $(, $param:ident : $param_ty:ty )*
|
||||
) -> $result:ty { $( $impl:tt )* }
|
||||
) => {
|
||||
impl<$trait_instance: $trait_name> $module<$trait_instance> {
|
||||
$(#[doc = $doc_attr])*
|
||||
$vis fn $name($origin: $origin_ty $(, $param: $param_ty )* ) -> $result {
|
||||
$( $impl )*
|
||||
}
|
||||
@@ -602,6 +607,7 @@ macro_rules! decl_module {
|
||||
$mod_type<$trait_instance: $trait_name>;
|
||||
$origin_type;
|
||||
$from;
|
||||
$(#[doc = $doc_attr])*
|
||||
$fn_vis fn $fn_name (
|
||||
$from $(, $param_name : $param )*
|
||||
) $( -> $result )* { $( $impl )* }
|
||||
|
||||
Reference in New Issue
Block a user