diff options
author | René Kijewski <kijewski@library.vetmed.fu-berlin.de> | 2022-02-03 18:24:14 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2022-02-03 18:48:27 +0100 |
commit | 082a9c2db9bb128956dd70f146af3e0228e4c433 (patch) | |
tree | e73b174899fbebe084ae75ecd6b9b4c5dcf96e08 /askama_shared/src | |
parent | 509d23a6c5e8637d0d060db286fad43c91c0fe38 (diff) | |
download | askama-082a9c2db9bb128956dd70f146af3e0228e4c433.tar.gz askama-082a9c2db9bb128956dd70f146af3e0228e4c433.tar.bz2 askama-082a9c2db9bb128956dd70f146af3e0228e4c433.zip |
Take reference to AST ident only once
Diffstat (limited to 'askama_shared/src')
-rw-r--r-- | askama_shared/src/input.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index ef27630..f7eac23 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -32,7 +32,12 @@ impl TemplateInput<'_> { // the proper type (list). let mut template_args = None; for attr in &ast.attrs { - if attr.path.is_ident("template") { + let ident = match attr.path.get_ident() { + Some(ident) => ident, + None => continue, + }; + + if ident == "template" { if template_args.is_some() { return Err("duplicated 'template' attribute".into()); } @@ -68,8 +73,12 @@ impl TemplateInput<'_> { .into()) } }; + let ident = match pair.path.get_ident() { + Some(ident) => ident, + None => unreachable!("not possible in syn::Meta::NameValue(…)"), + }; - if pair.path.is_ident("path") { + if ident == "path" { if let syn::Lit::Str(ref s) = pair.lit { if source.is_some() { return Err("must specify 'source' or 'path', not both".into()); @@ -78,7 +87,7 @@ impl TemplateInput<'_> { } else { return Err("template path must be string literal".into()); } - } else if pair.path.is_ident("source") { + } else if ident == "source" { if let syn::Lit::Str(ref s) = pair.lit { if source.is_some() { return Err("must specify 'source' or 'path', not both".into()); @@ -87,36 +96,32 @@ impl TemplateInput<'_> { } else { return Err("template source must be string literal".into()); } - } else if pair.path.is_ident("print") { + } else if ident == "print" { if let syn::Lit::Str(ref s) = pair.lit { print = s.value().parse()?; } else { return Err("print value must be string literal".into()); } - } else if pair.path.is_ident("escape") { + } else if ident == "escape" { if let syn::Lit::Str(ref s) = pair.lit { escaping = Some(s.value()); } else { return Err("escape value must be string literal".into()); } - } else if pair.path.is_ident("ext") { + } else if ident == "ext" { if let syn::Lit::Str(ref s) = pair.lit { ext = Some(s.value()); } else { return Err("ext value must be string literal".into()); } - } else if pair.path.is_ident("syntax") { + } else if ident == "syntax" { if let syn::Lit::Str(ref s) = pair.lit { syntax = Some(s.value()) } else { return Err("syntax value must be string literal".into()); } } else { - return Err(format!( - "unsupported attribute key '{}' found", - pair.path.to_token_stream() - ) - .into()); + return Err(format!("unsupported attribute key {:?} found", ident).into()); } } |