From 99a1db806c68c9030d48049e18b2f00c3e6f1ce7 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 24 Feb 2021 11:55:17 +0000 Subject: [PATCH] Simplify creating and using doc_attributes vec --- actix-web-codegen/src/route.rs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index e6a424781..e3c5f0368 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -229,13 +229,12 @@ impl Route { // // Note that multi line doc comments are converted to multiple doc // attributes. - let mut doc_attributes = Vec::new(); - for attr in &ast.attrs { - if attr.path.get_ident().is_ident("doc") { - doc_attribute.push(attr.clone()); - } - } - } + let doc_attributes = ast + .attrs + .iter() + .filter(|attr| attr.path.is_ident("doc")) + .cloned() + .collect(); let args = Args::new(args, method)?; if args.methods.is_empty() { @@ -264,7 +263,7 @@ impl Route { args, ast, resource_type, - doc_attributes: doc_attribute, + doc_attributes, }) } } @@ -304,13 +303,8 @@ impl ToTokens for Route { } }; - let doc_comment_token_stream: TokenStream2 = doc_attribute - .iter() - .map(ToTokens::to_token_stream) - .collect(); - let stream = quote! { - #(#doc_comments)* + #(#doc_attributes)* #[allow(non_camel_case_types, missing_docs)] pub struct #name;