diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-21 12:19:54 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-21 12:19:54 +0200 |
commit | 31b90ccc657a5468de6bdffea8d309f502cd0d07 (patch) | |
tree | 5b5689f15dfb2cdcc27eca10ef39212dd18db4f2 /askama_shared/src/escaping.rs | |
parent | f05a924c49afb537b624cfe3cbef3a95b13759a2 (diff) | |
download | askama-31b90ccc657a5468de6bdffea8d309f502cd0d07.tar.gz askama-31b90ccc657a5468de6bdffea8d309f502cd0d07.tar.bz2 askama-31b90ccc657a5468de6bdffea8d309f502cd0d07.zip |
Fix formatting with cargo fmt
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/escaping.rs | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/askama_shared/src/escaping.rs b/askama_shared/src/escaping.rs index 896fc2a..e22e0ce 100644 --- a/askama_shared/src/escaping.rs +++ b/askama_shared/src/escaping.rs @@ -1,13 +1,18 @@ use std::fmt::{self, Display, Formatter}; - #[derive(Debug, PartialEq)] -pub enum MarkupDisplay<T> where T: Display { +pub enum MarkupDisplay<T> +where + T: Display, +{ Safe(T), Unsafe(T), } -impl<T> MarkupDisplay<T> where T: Display { +impl<T> MarkupDisplay<T> +where + T: Display, +{ pub fn mark_safe(self) -> MarkupDisplay<T> { match self { MarkupDisplay::Unsafe(t) => MarkupDisplay::Safe(t), @@ -21,13 +26,19 @@ impl<T> MarkupDisplay<T> where T: Display { } } -impl<T> From<T> for MarkupDisplay<T> where T: Display { +impl<T> From<T> for MarkupDisplay<T> +where + T: Display, +{ fn from(t: T) -> MarkupDisplay<T> { MarkupDisplay::Unsafe(t) } } -impl<T> Display for MarkupDisplay<T> where T: Display { +impl<T> Display for MarkupDisplay<T> +where + T: Display, +{ fn fmt(&self, f: &mut Formatter) -> fmt::Result { match *self { MarkupDisplay::Unsafe(_) => write!(f, "{}", escape(self.unsafe_string())), @@ -36,7 +47,6 @@ impl<T> Display for MarkupDisplay<T> where T: Display { } } - fn escapable(b: u8) -> bool { match b { b'<' | b'>' | b'&' | b'"' | b'\'' | b'/' => true, @@ -65,12 +75,24 @@ pub fn escape(s: String) -> String { } start = *idx + 1; match bytes[*idx] { - b'<' => { res.extend(b"<"); }, - b'>' => { res.extend(b">"); }, - b'&' => { res.extend(b"&"); }, - b'"' => { res.extend(b"""); }, - b'\'' => { res.extend(b"'"); }, - b'/' => { res.extend(b"/"); }, + b'<' => { + res.extend(b"<"); + } + b'>' => { + res.extend(b">"); + } + b'&' => { + res.extend(b"&"); + } + b'"' => { + res.extend(b"""); + } + b'\'' => { + res.extend(b"'"); + } + b'/' => { + res.extend(b"/"); + } _ => panic!("incorrect indexing"), } } @@ -81,7 +103,6 @@ pub fn escape(s: String) -> String { String::from_utf8(res).unwrap() } - #[cfg(test)] mod tests { use super::*; |