aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-03-07 21:07:01 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-03-07 21:07:01 +0100
commitd65d08b9378d23ba3fa5b66739f6c78de466fdb8 (patch)
tree4c70596cf135f7ea1cb72dafcc8b9d1eb1072e06 /askama_derive
parent0eeb5d1b2d998f3ea56b5682f618a57443cd8aef (diff)
downloadaskama-d65d08b9378d23ba3fa5b66739f6c78de466fdb8.tar.gz
askama-d65d08b9378d23ba3fa5b66739f6c78de466fdb8.tar.bz2
askama-d65d08b9378d23ba3fa5b66739f6c78de466fdb8.zip
Panic with better message if template attribute is not found (fixes #3)
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/src/lib.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index 752978e..f823299 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -19,9 +19,16 @@ struct TemplateMeta {
// in the parsed struct or enum. Will panic if it does not find the required
// template path, or if the `print` key has an unexpected value.
fn get_template_meta(ast: &syn::DeriveInput) -> TemplateMeta {
+ let attr = ast.attrs.iter().find(|a| a.name() == "template");
+ if attr.is_none() {
+ let msg = format!("'template' attribute not found on struct '{}'",
+ ast.ident.as_ref());
+ panic!(msg);
+ }
+
+ let attr = attr.unwrap();
let mut path = None;
let mut print = "none".to_string();
- let attr = ast.attrs.iter().find(|a| a.name() == "template").unwrap();
if let syn::MetaItem::List(_, ref inner) = attr.value {
for nm_item in inner {
if let syn::NestedMetaItem::MetaItem(ref item) = *nm_item {