aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
authorLibravatar mash <mashedcode@users.noreply.github.com>2018-06-29 13:44:38 +0000
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-07-02 09:25:27 +0200
commit23db04ea5ff9cca2008a1a3bb6d0dce452f519d3 (patch)
treeb79be942582a5928ef04552520c55b1a77c96c28 /askama_derive/src
parent4ead8e8c9302ce67d322e51909f0897082483ca3 (diff)
downloadaskama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.tar.gz
askama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.tar.bz2
askama-23db04ea5ff9cca2008a1a3bb6d0dce452f519d3.zip
Improve field type determination
Diffstat (limited to 'askama_derive/src')
-rw-r--r--askama_derive/src/input.rs17
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,