diff options
author | vallentin <mail@vallentin.dev> | 2020-12-29 22:59:11 +0100 |
---|---|---|
committer | Christian Vallentin <vallentinsource@gmail.com> | 2020-12-29 23:48:41 +0100 |
commit | 6e3fdb47016731aa47ff1240fbef3014613ab876 (patch) | |
tree | 10a232d862805b962d6895a688d647befa70c51a /askama_shared/src | |
parent | 7e9357795a9259ca41eee7249441a920fab8db2f (diff) | |
download | askama-6e3fdb47016731aa47ff1240fbef3014613ab876.tar.gz askama-6e3fdb47016731aa47ff1240fbef3014613ab876.tar.bz2 askama-6e3fdb47016731aa47ff1240fbef3014613ab876.zip |
Refactored into filters constant
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index f32542a..0e58de1 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -1193,7 +1193,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { return Err("the `yaml` filter requires the `serde-yaml` feature to be enabled".into()); } - if name == "escape" || name == "safe" || name == "e" || name == "json" { + const FILTERS: [&str; 4] = ["safe", "escape", "e", "json"]; + if FILTERS.contains(&name) { buf.write(&format!( "::askama::filters::{}({}, ", name, self.input.escaper @@ -1206,13 +1207,10 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { self._visit_args(buf, args)?; buf.write(")?"); - Ok( - if name == "safe" || name == "escape" || name == "e" || name == "json" { - DisplayWrap::Wrapped - } else { - DisplayWrap::Unwrapped - }, - ) + Ok(match FILTERS.contains(&name) { + true => DisplayWrap::Wrapped, + false => DisplayWrap::Unwrapped, + }) } fn _visit_format_filter( |