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 | |
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/error.rs | 16 | ||||
-rw-r--r-- | askama_shared/src/escaping.rs | 47 | ||||
-rw-r--r-- | askama_shared/src/filters/json.rs | 4 | ||||
-rw-r--r-- | askama_shared/src/filters/mod.rs | 18 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 2 | ||||
-rw-r--r-- | askama_shared/src/path.rs | 10 |
6 files changed, 58 insertions, 39 deletions
diff --git a/askama_shared/src/error.rs b/askama_shared/src/error.rs index cdd6b55..df175cd 100644 --- a/askama_shared/src/error.rs +++ b/askama_shared/src/error.rs @@ -1,5 +1,5 @@ +use std::error::Error as ErrorTrait; use std::fmt::{self, Display}; -use std::error::{Error as ErrorTrait}; pub type Result<I> = ::std::result::Result<I, Error>; @@ -23,7 +23,7 @@ pub type Result<I> = ::std::result::Result<I, Error>; /// bring to this crate are small, which is why /// `std::error::Error` was used. /// -#[derive(Debug, )] +#[derive(Debug)] pub enum Error { /// formatting error Fmt(fmt::Error), @@ -40,22 +40,21 @@ pub enum Error { } impl ErrorTrait for Error { - fn description(&self) -> &str { match *self { Error::Fmt(ref err) => err.description(), #[cfg(feature = "serde-json")] Error::Json(ref err) => err.description(), - _ => "unknown error: __Nonexhaustive" + _ => "unknown error: __Nonexhaustive", } } fn cause(&self) -> Option<&ErrorTrait> { match *self { Error::Fmt(ref err) => err.cause(), - #[cfg(feature = "serde-json")] + #[cfg(feature = "serde-json")] Error::Json(ref err) => err.cause(), - _ => None + _ => None, } } } @@ -67,7 +66,7 @@ impl Display for Error { #[cfg(feature = "serde-json")] Error::Json(ref err) => write!(formatter, "json conversion error: {}", err), - _ => write!(formatter, "unknown error: __Nonexhaustive") + _ => write!(formatter, "unknown error: __Nonexhaustive"), } } } @@ -85,11 +84,10 @@ impl From<::serde_json::Error> for Error { } } - #[cfg(test)] mod tests { use super::Error; trait AssertSendSyncStatic: Send + Sync + 'static {} impl AssertSendSyncStatic for Error {} -}
\ No newline at end of file +} 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::*; diff --git a/askama_shared/src/filters/json.rs b/askama_shared/src/filters/json.rs index 5d1b3ac..ffc5310 100644 --- a/askama_shared/src/filters/json.rs +++ b/askama_shared/src/filters/json.rs @@ -1,9 +1,8 @@ +use error::{Error, Result}; use serde::Serialize; use serde_json; -use error::{Error, Result}; use MarkupDisplay; - /// Serialize to JSON (requires `serde-json` feature) /// /// ## Errors @@ -17,7 +16,6 @@ pub fn json<S: Serialize>(s: &S) -> Result<MarkupDisplay<String>> { } } - #[cfg(test)] mod tests { use super::*; diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs index 32a7ccc..9fc03b6 100644 --- a/askama_shared/src/filters/mod.rs +++ b/askama_shared/src/filters/mod.rs @@ -11,9 +11,8 @@ pub use self::json::json; use std::fmt; -use escaping::{self, MarkupDisplay}; use super::Result; - +use escaping::{self, MarkupDisplay}; // This is used by the code generator to decide whether a named filter is part of // Askama or should refer to a local `filters` module. It should contain all the @@ -32,11 +31,10 @@ pub const BUILT_IN_FILTERS: [&str; 10] = [ "json", // Optional feature; reserve the name anyway ]; - pub fn safe<D, I>(v: I) -> Result<MarkupDisplay<D>> where D: fmt::Display, - MarkupDisplay<D>: From<I> + MarkupDisplay<D>: From<I>, { let res: MarkupDisplay<D> = v.into(); Ok(res.mark_safe()) @@ -46,7 +44,7 @@ where pub fn escape<D, I>(i: I) -> Result<MarkupDisplay<String>> where D: fmt::Display, - MarkupDisplay<D>: From<I> + MarkupDisplay<D>: From<I>, { let md: MarkupDisplay<D> = i.into(); Ok(MarkupDisplay::Safe(escaping::escape(md.unsafe_string()))) @@ -56,7 +54,7 @@ where pub fn e<D, I>(i: I) -> Result<MarkupDisplay<String>> where D: fmt::Display, - MarkupDisplay<D>: From<I> + MarkupDisplay<D>: From<I>, { escape(i) } @@ -99,9 +97,10 @@ pub fn trim(s: &fmt::Display) -> Result<String> { /// Joins iterable into a string separated by provided argument pub fn join<T, I, S>(input: I, separator: S) -> Result<String> - where T: fmt::Display, - I: Iterator<Item = T>, - S: AsRef<str> +where + T: fmt::Display, + I: Iterator<Item = T>, + S: AsRef<str>, { let separator: &str = separator.as_ref(); @@ -118,7 +117,6 @@ pub fn join<T, I, S>(input: I, separator: S) -> Result<String> Ok(rv) } - #[cfg(test)] mod tests { use super::*; diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index cbb99d9..9427dff 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -5,8 +5,8 @@ extern crate serde; #[cfg(feature = "serde-json")] extern crate serde_json; -pub use escaping::MarkupDisplay; pub use error::{Error, Result}; +pub use escaping::MarkupDisplay; mod error; pub mod filters; pub mod path; diff --git a/askama_shared/src/path.rs b/askama_shared/src/path.rs index c84575f..8b92250 100644 --- a/askama_shared/src/path.rs +++ b/askama_shared/src/path.rs @@ -10,7 +10,7 @@ pub fn get_template_source(tpl_path: &Path) -> String { Err(_) => { let msg = format!("unable to open template file '{}'", &path.to_str().unwrap()); panic!(msg) - }, + } Ok(f) => f, }; let mut s = String::new(); @@ -38,7 +38,11 @@ pub fn find_template_from_path(path: &str, start_at: Option<&Path>) -> PathBuf { if fs_abs_path.exists() { path.to_owned() } else { - panic!(format!("template {:?} not found at {:?}", path.to_str().unwrap(), fs_abs_path)); + panic!(format!( + "template {:?} not found at {:?}", + path.to_str().unwrap(), + fs_abs_path + )); } } @@ -50,8 +54,8 @@ pub fn template_dir() -> PathBuf { #[cfg(test)] mod tests { - use super::{find_template_from_path, get_template_source}; use super::Path; + use super::{find_template_from_path, get_template_source}; #[test] fn get_source() { |