Apply cargo fmt (#1146)

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
This commit is contained in:
Alexandru Vasile
2023-08-28 16:03:29 +03:00
committed by GitHub
parent b413e5e84e
commit 91a56fd580
18 changed files with 157 additions and 74 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ pub fn generate_calls(
return Err(CodegenError::MissingCallMetadata(
pallet_name.into(),
call_name.to_string(),
))
));
};
let fn_name = format_ident!("{}", variant_name.to_snake_case());
// Propagate the documentation just to `TransactionApi` methods, while
+28 -22
View File
@@ -45,31 +45,37 @@ pub fn generate_constants(
return Ok(quote!());
}
let constant_fns = pallet.constants().map(|constant| {
let fn_name = format_ident!("{}", constant.name().to_snake_case());
let pallet_name = pallet.name();
let constant_name = constant.name();
let Some(constant_hash) = pallet.constant_hash(constant_name) else {
return Err(CodegenError::MissingConstantMetadata(constant_name.into(), pallet_name.into()));
};
let constant_fns = pallet
.constants()
.map(|constant| {
let fn_name = format_ident!("{}", constant.name().to_snake_case());
let pallet_name = pallet.name();
let constant_name = constant.name();
let Some(constant_hash) = pallet.constant_hash(constant_name) else {
return Err(CodegenError::MissingConstantMetadata(
constant_name.into(),
pallet_name.into(),
));
};
let return_ty = type_gen.resolve_type_path(constant.ty());
let docs = constant.docs();
let docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
let return_ty = type_gen.resolve_type_path(constant.ty());
let docs = constant.docs();
let docs = should_gen_docs
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
Ok(quote! {
#docs
pub fn #fn_name(&self) -> #crate_path::constants::Address<#return_ty> {
#crate_path::constants::Address::new_static(
#pallet_name,
#constant_name,
[#(#constant_hash,)*]
)
}
Ok(quote! {
#docs
pub fn #fn_name(&self) -> #crate_path::constants::Address<#return_ty> {
#crate_path::constants::Address::new_static(
#pallet_name,
#constant_name,
[#(#constant_hash,)*]
)
}
})
})
}).collect::<Result<Vec<_>, _>>()?;
.collect::<Result<Vec<_>, _>>()?;
Ok(quote! {
pub mod constants {
+1 -1
View File
@@ -47,7 +47,7 @@ pub fn generate_events(
) -> Result<TokenStream2, CodegenError> {
// Early return if the pallet has no events.
let Some(event_ty) = pallet.event_ty_id() else {
return Ok(quote!())
return Ok(quote!());
};
let struct_defs = super::generate_structs_from_variants(
+4 -1
View File
@@ -89,7 +89,10 @@ fn generate_storage_entry_fns(
let pallet_name = pallet.name();
let storage_name = storage_entry.name();
let Some(storage_hash) = pallet.storage_hash(storage_name) else {
return Err(CodegenError::MissingStorageMetadata(pallet_name.into(), storage_name.into()));
return Err(CodegenError::MissingStorageMetadata(
pallet_name.into(),
storage_name.into(),
));
};
let snake_case_name = storage_entry.name().to_snake_case();
+13 -3
View File
@@ -187,11 +187,21 @@ impl TypeSubstitutes {
src_path: &syn::Path,
target_path: &syn::Path,
) -> Result<TypeParamMapping, TypeSubstitutionError> {
let Some(syn::PathSegment { arguments: src_path_args, .. }) = src_path.segments.last() else {
let Some(syn::PathSegment {
arguments: src_path_args,
..
}) = src_path.segments.last()
else {
return Err(TypeSubstitutionError::EmptySubstitutePath(src_path.span()));
};
let Some(syn::PathSegment { arguments: target_path_args, .. }) = target_path.segments.last() else {
return Err(TypeSubstitutionError::EmptySubstitutePath(target_path.span()));
let Some(syn::PathSegment {
arguments: target_path_args,
..
}) = target_path.segments.last()
else {
return Err(TypeSubstitutionError::EmptySubstitutePath(
target_path.span(),
));
};
// Get hold of the generic args for the "from" type, erroring if they aren't valid.