From 471b848f612b9210c9ad873443c5f1fc30ab6d76 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 25 May 2018 17:38:43 +0200 Subject: Extract path rooting to simplify trait_name_for_path() --- askama_derive/src/generator.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'askama_derive/src/generator.rs') diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 3e9dcc3..8334964 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -79,21 +79,21 @@ impl<'a> State<'a> { nodes, blocks, macros, - trait_name: trait_name_for_path(&base, &input.path), + trait_name: match base { + Some(user_path) => trait_name_for_path( + &path::find_template_from_path(user_path, Some(&input.path)) + ), + None => trait_name_for_path(&input.path), + }, derived: base.is_some(), } } } -fn trait_name_for_path(base: &Option<&str>, path: &Path) -> String { - let rooted_path = match *base { - Some(user_path) => path::find_template_from_path(user_path, Some(path)), - _ => path.to_path_buf(), - }; - +fn trait_name_for_path(path: &Path) -> String { let mut res = String::new(); res.push_str("TraitFrom"); - for c in rooted_path.to_string_lossy().chars() { + for c in path.to_string_lossy().chars() { if c.is_alphanumeric() { res.push(c); } else { -- cgit