code cleaning

This commit is contained in:
vms 2021-04-01 12:20:52 +03:00
parent 8e2318dc77
commit b34a9fc90b
5 changed files with 29 additions and 34 deletions

View File

@ -122,7 +122,7 @@ pub(super) fn generate_test_glue_code(
#app_service_ctor
#module_ctors
#(#module_ctors)*
#original_block
}
@ -157,22 +157,19 @@ fn generate_app_service_ctor(config_path: &str, modules_dir: &PathBuf) -> TokenS
fn generate_module_ctors<'n>(
module_names: impl ExactSizeIterator<Item = &'n str>,
) -> TResult<TokenStream> {
let mut module_ctors = Vec::with_capacity(module_names.len());
for name in module_names {
// TODO: optimize these two call because they are called twice for each module name
// and internally allocate memory in format call.
let module_name = fce_test::utils::generate_module_name(&name)?;
let struct_name = fce_test::utils::generate_struct_name(&name)?;
let name_for_user = fce_test::utils::new_ident(&name)?;
) -> TResult<Vec<TokenStream>> {
module_names
.map(|name| -> TResult<_> {
// TODO: optimize these two call because they are called twice for each module name
// and internally allocate memory in format call.
let module_name = fce_test::utils::generate_module_name(&name)?;
let struct_name = fce_test::utils::generate_struct_name(&name)?;
let name_for_user = fce_test::utils::new_ident(&name)?;
let module_ctor =
quote! { let mut #name_for_user = #module_name::#struct_name::new(fce.clone()); };
let module_ctor =
quote! { let mut #name_for_user = #module_name::#struct_name::new(fce.clone()); };
module_ctors.push(module_ctor);
}
let module_ctors = quote! { #(#module_ctors),* };
Ok(module_ctors)
Ok(module_ctor)
})
.collect::<TResult<_>>()
}

View File

@ -31,7 +31,7 @@ pub(super) fn generate_module_methods<'m, 'r>(
records: &'r FCERecordTypes,
) -> TResult<Vec<TokenStream>> {
method_signatures
.map(|signature| -> TResult<TokenStream> {
.map(|signature| -> TResult<_> {
let func_name = utils::new_ident(&signature.name)?;
let arguments = generate_arguments(signature.arguments.iter(), records)?;
let output_type = generate_output_type(&signature.outputs, records)?;
@ -45,7 +45,7 @@ pub(super) fn generate_module_methods<'m, 'r>(
Ok(module_method)
})
.collect::<Result<Vec<_>, _>>()
.collect::<TResult<Vec<_>>>()
}
fn generate_fce_call(
@ -128,16 +128,15 @@ fn generate_arguments<'a, 'r>(
arguments: impl ExactSizeIterator<Item = &'a IFunctionArg>,
records: &'r FCERecordTypes,
) -> TResult<Vec<TokenStream>> {
let mut result = Vec::with_capacity(arguments.len());
for argument in arguments {
let arg_name = utils::new_ident(&argument.name)?;
let arg_type = utils::itype_to_tokens(&argument.ty, records)?;
arguments
.map(|argument| -> TResult<_> {
let arg_name = utils::new_ident(&argument.name)?;
let arg_type = utils::itype_to_tokens(&argument.ty, records)?;
let arg = quote! { #arg_name: #arg_type };
result.push(arg);
}
Ok(result)
let arg = quote! { #arg_name: #arg_type };
Ok(arg)
})
.collect::<TResult<Vec<_>>>()
}
fn generate_output_type(output_types: &[IType], records: &FCERecordTypes) -> TResult<TokenStream> {

View File

@ -26,7 +26,7 @@ use quote::quote;
pub(super) fn generate_records(records: &FCERecordTypes) -> TResult<Vec<TokenStream>> {
use std::ops::Deref;
records.iter().map(|(_, record)| -> TResult<TokenStream> {
records.iter().map(|(_, record)| -> TResult<_> {
let record_name_ident = utils::generate_record_name(&record.name)?;
let fields = prepare_field(record.fields.deref().iter(), records)?;
@ -39,7 +39,7 @@ pub(super) fn generate_records(records: &FCERecordTypes) -> TResult<Vec<TokenStr
Ok(generated_record)
}
).collect::<Result<Vec<_>, _>>()
).collect::<TResult<Vec<_>>>()
}
fn prepare_field<'f>(
@ -47,7 +47,7 @@ fn prepare_field<'f>(
records: &FCERecordTypes,
) -> TResult<Vec<TokenStream>> {
fields
.map(|field| -> TResult<TokenStream> {
.map(|field| -> TResult<_> {
let field_name = utils::new_ident(&field.name)?;
let field_type = utils::itype_to_tokens(&field.ty, records)?;
@ -55,5 +55,5 @@ fn prepare_field<'f>(
Ok(generated_field)
})
.collect::<Result<Vec<_>, _>>()
.collect::<TResult<Vec<_>>>()
}

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
#![doc(html_root_url = "https://docs.rs/fluence-sdk-macro/0.5.0")]
#![deny(
dead_code,
nonstandard_style,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
#![doc(html_root_url = "https://docs.rs/fluence/0.5.0")]
#![doc(html_root_url = "https://docs.rs/fluence-test/0.5.0")]
#![deny(
dead_code,
nonstandard_style,