diff options
author | mash <mashedcode@users.noreply.github.com> | 2018-06-29 13:44:38 +0000 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-07-02 09:25:27 +0200 |
commit | 23db04ea5ff9cca2008a1a3bb6d0dce452f519d3 (patch) | |
tree | b79be942582a5928ef04552520c55b1a77c96c28 /askama_derive | |
parent | 4ead8e8c9302ce67d322e51909f0897082483ca3 (diff) | |
download | askama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.tar.gz askama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.tar.bz2 askama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.zip |
Improve field type determination
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/input.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index cf1ad90..93d5e17 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -102,13 +102,20 @@ impl<'a> TemplateInput<'a> { syn::Data::Struct(syn::DataStruct { fields: syn::Fields::Named(ref fields), .. - }) => fields.named.iter().filter_map(|f| { - f.ident - .as_ref() - .and_then(|name| if name == "_parent" { Some(&f.ty) } else { None }) + }) => fields.named.iter().find(|f| { + if let Some(field_name) = f.ident.as_ref() { + field_name == "_parent" + } else { + false + } }), _ => panic!("derive(Template) only works for struct items"), - }.next(); + }; + let parent = if let Some(parent) = parent { + Some(&parent.ty) + } else { + None + }; TemplateInput { ast, |