aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:47:29 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:47:29 +0200
commit3ba96cabca53aa660f3dc935e3fd3e58eeb7b142 (patch)
tree96786f2ff1b88027360247a5005ab326070e1c62 /askama_derive
parent9e95100bf9457da07a1632b4c0bb44b5ecf5d1be (diff)
downloadaskama-3ba96cabca53aa660f3dc935e3fd3e58eeb7b142.tar.gz
askama-3ba96cabca53aa660f3dc935e3fd3e58eeb7b142.tar.bz2
askama-3ba96cabca53aa660f3dc935e3fd3e58eeb7b142.zip
Further simplify code to find parent fields
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/src/input.rs17
1 files changed, 5 insertions, 12 deletions
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,