From 23db04ea5ff9cca2008a1a3bb6d0dce452f519d3 Mon Sep 17 00:00:00 2001 From: mash Date: Fri, 29 Jun 2018 13:44:38 +0000 Subject: Improve field type determination --- askama_derive/src/input.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'askama_derive/src') 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, -- cgit