From e3895e88426fa7301b56cc4705cc6dcc1e2dac0c Mon Sep 17 00:00:00 2001 From: Andrey Zgarbul Date: Tue, 4 Jun 2024 09:04:07 +0300 Subject: [PATCH] clean --- src/generate/peripheral.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/generate/peripheral.rs b/src/generate/peripheral.rs index cc95ae74..6488a670 100644 --- a/src/generate/peripheral.rs +++ b/src/generate/peripheral.rs @@ -78,13 +78,13 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result /// no stolen instances are passed to such software. }; - let per_to_tokens = |feature_attribute: &TokenStream, + let per_to_tokens = |out: &mut TokenStream, + feature_attribute: &TokenStream, description: &str, p_ty: &Ident, doc_alias: Option, - address: LitInt| - -> TokenStream { - let mut tokens = if config.raw_access { + address: LitInt| { + out.extend(if config.raw_access { quote! { #[doc = #description] #doc_alias @@ -149,8 +149,8 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result } } } - }; - tokens.extend(quote! { + }); + out.extend(quote! { #feature_attribute impl core::fmt::Debug for #p_ty { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { @@ -158,7 +158,6 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result } } }); - tokens }; match &p { @@ -178,13 +177,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result feature_attribute_n.extend(quote! { #[cfg(feature = #p_feature)] }) }; // Insert the peripherals structure - out.extend(per_to_tokens( + per_to_tokens( + &mut out, &feature_attribute_n, description, &p_ty, doc_alias, address, - )); + ); } let feature_any_attribute = quote! {#[cfg(any(#(feature = #feature_names),*))]}; @@ -207,13 +207,14 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result feature_attribute.extend(quote! { #[cfg(feature = #p_feature)] }) }; // Insert the peripheral structure - out.extend(per_to_tokens( + per_to_tokens( + &mut out, &feature_attribute, &description, &p_ty, None, address, - )); + ); // Derived peripherals may not require re-implementation, and will instead // use a single definition of the non-derived version.