From 3ba96cabca53aa660f3dc935e3fd3e58eeb7b142 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 2 Jul 2018 09:47:29 +0200 Subject: Further simplify code to find parent fields --- askama_derive/src/input.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'askama_derive') diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index 683c345..ce004a8 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -100,20 +100,13 @@ impl<'a> TemplateInput<'a> { syn::Data::Struct(syn::DataStruct { fields: syn::Fields::Named(ref fields), .. - }) => fields.named.iter().find(|f| { - if let Some(field_name) = f.ident.as_ref() { - field_name == "_parent" - } else { - false - } - }), + }) => fields + .named + .iter() + .find(|f| f.ident.as_ref().filter(|name| *name == "_parent").is_some()) + .map(|f| &f.ty), _ => panic!("derive(Template) only works for struct items"), }; - let parent = if let Some(parent) = parent { - Some(&parent.ty) - } else { - None - }; TemplateInput { ast, -- cgit