From 3496be9d0c3f090ceb0a99fcdd8bcb93750909dc Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Fri, 5 Feb 2021 10:41:01 +0800 Subject: [PATCH] fix a little string & use map_or_else instead of if-else --- actix-web-codegen/src/route.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/actix-web-codegen/src/route.rs b/actix-web-codegen/src/route.rs index c15650202..ac0b7cea1 100644 --- a/actix-web-codegen/src/route.rs +++ b/actix-web-codegen/src/route.rs @@ -117,7 +117,7 @@ impl Args { } else { return Err(syn::Error::new_spanned( nv.lit, - "Attribute endpoint expects literal string!", + "Attribute name expects literal string!", )); } } else if nv.path.is_ident("guard") { @@ -296,11 +296,9 @@ impl ToTokens for Route { resource_type, doc_attributes, } = self; - let resource_name = if let Some(resource_name) = resource_name { - resource_name.value() - } else { - name.to_string() - }; + let resource_name = resource_name + .as_ref() + .map_or_else(|| name.to_string(), |n| n.value()); let method_guards = { let mut others = methods.iter(); // unwrapping since length is checked to be at least one