diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-05-25 17:38:43 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-05-25 18:17:12 +0200 |
commit | 471b848f612b9210c9ad873443c5f1fc30ab6d76 (patch) | |
tree | c329773ea6d50e94fc8e8c8d010efd21f45a020c /askama_derive/src | |
parent | c2576e0a7a3e029561ba64327f92d3340bf05560 (diff) | |
download | askama-471b848f612b9210c9ad873443c5f1fc30ab6d76.tar.gz askama-471b848f612b9210c9ad873443c5f1fc30ab6d76.tar.bz2 askama-471b848f612b9210c9ad873443c5f1fc30ab6d76.zip |
Extract path rooting to simplify trait_name_for_path()
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/generator.rs | 16 |
1 files changed, 8 insertions, 8 deletions
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 { |