From 5549f9a3cd94e3cd6700067b1c74194dadb58a0f Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 7 Dec 2018 15:52:26 +0100 Subject: Use 2018 edition idioms --- askama_shared/src/error.rs | 4 ++-- askama_shared/src/filters/json.rs | 4 ++-- askama_shared/src/filters/mod.rs | 24 ++++++++++++------------ askama_shared/src/lib.rs | 14 ++++---------- 4 files changed, 20 insertions(+), 26 deletions(-) (limited to 'askama_shared/src') diff --git a/askama_shared/src/error.rs b/askama_shared/src/error.rs index 90ba571..650e275 100644 --- a/askama_shared/src/error.rs +++ b/askama_shared/src/error.rs @@ -49,7 +49,7 @@ impl ErrorTrait for Error { } } - fn cause(&self) -> Option<&ErrorTrait> { + fn cause(&self) -> Option<&dyn ErrorTrait> { match *self { Error::Fmt(ref err) => err.cause(), #[cfg(feature = "serde_json")] @@ -60,7 +60,7 @@ impl ErrorTrait for Error { } impl Display for Error { - fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Error::Fmt(ref err) => write!(formatter, "formatting error: {}", err), diff --git a/askama_shared/src/filters/json.rs b/askama_shared/src/filters/json.rs index 2df6db6..56053be 100644 --- a/askama_shared/src/filters/json.rs +++ b/askama_shared/src/filters/json.rs @@ -1,6 +1,6 @@ -use error::{Error, Result}; +use crate::error::{Error, Result}; use serde::Serialize; -use MarkupDisplay; +use askama_escape::MarkupDisplay; /// Serialize to JSON (requires `serde_json` feature) /// diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs index 0be9f95..85ff8b2 100644 --- a/askama_shared/src/filters/mod.rs +++ b/askama_shared/src/filters/mod.rs @@ -97,7 +97,7 @@ pub fn format() {} /// /// A single newline becomes an HTML line break `
` and a new line /// followed by a blank line becomes a paragraph break `

`. -pub fn linebreaks(s: &fmt::Display) -> Result { +pub fn linebreaks(s: &dyn fmt::Display) -> Result { let s = s.to_string(); let linebroken = s.replace("\n\n", "

").replace("\n", "
"); @@ -105,41 +105,41 @@ pub fn linebreaks(s: &fmt::Display) -> Result { } /// Converts all newlines in a piece of plain text to HTML line breaks -pub fn linebreaksbr(s: &fmt::Display) -> Result { +pub fn linebreaksbr(s: &dyn fmt::Display) -> Result { let s = s.to_string(); Ok(s.replace("\n", "
")) } /// Converts to lowercase -pub fn lower(s: &fmt::Display) -> Result { +pub fn lower(s: &dyn fmt::Display) -> Result { let s = s.to_string(); Ok(s.to_lowercase()) } /// Alias for the `lower()` filter -pub fn lowercase(s: &fmt::Display) -> Result { +pub fn lowercase(s: &dyn fmt::Display) -> Result { lower(s) } /// Converts to uppercase -pub fn upper(s: &fmt::Display) -> Result { +pub fn upper(s: &dyn fmt::Display) -> Result { let s = s.to_string(); Ok(s.to_uppercase()) } /// Alias for the `upper()` filter -pub fn uppercase(s: &fmt::Display) -> Result { +pub fn uppercase(s: &dyn fmt::Display) -> Result { upper(s) } /// Strip leading and trailing whitespace -pub fn trim(s: &fmt::Display) -> Result { +pub fn trim(s: &dyn fmt::Display) -> Result { let s = s.to_string(); Ok(s.trim().to_owned()) } /// Limit string length, appends '...' if truncated -pub fn truncate(s: &fmt::Display, len: &usize) -> Result { +pub fn truncate(s: &dyn fmt::Display, len: &usize) -> Result { let mut s = s.to_string(); if s.len() < *len { Ok(s) @@ -151,7 +151,7 @@ pub fn truncate(s: &fmt::Display, len: &usize) -> Result { } /// Indent lines with `width` spaces -pub fn indent(s: &fmt::Display, width: &usize) -> Result { +pub fn indent(s: &dyn fmt::Display, width: &usize) -> Result { let s = s.to_string(); let mut indented = String::new(); @@ -216,7 +216,7 @@ where } /// Capitalize a value. The first character will be uppercase, all others lowercase. -pub fn capitalize(s: &fmt::Display) -> Result { +pub fn capitalize(s: &dyn fmt::Display) -> Result { let mut s = s.to_string(); match s.get_mut(0..1).map(|s| { @@ -234,7 +234,7 @@ pub fn capitalize(s: &fmt::Display) -> Result { } /// Centers the value in a field of a given width -pub fn center(s: &fmt::Display, l: usize) -> Result { +pub fn center(s: &dyn fmt::Display, l: usize) -> Result { let s = s.to_string(); let len = s.len(); @@ -261,7 +261,7 @@ pub fn center(s: &fmt::Display, l: usize) -> Result { } /// Count the words in that string -pub fn wordcount(s: &fmt::Display) -> Result { +pub fn wordcount(s: &dyn fmt::Display) -> Result { let s = s.to_string(); Ok(s.split_whitespace().count()) diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index adb41b5..850cb8b 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -1,14 +1,8 @@ #![cfg_attr(feature = "cargo-clippy", allow(unused_parens))] - -extern crate askama_escape; -extern crate humansize; -extern crate num_traits; -extern crate serde; #[macro_use] extern crate serde_derive; -#[cfg(feature = "serde_json")] -extern crate serde_json; -extern crate toml; + +use toml; use std::env; use std::fs; @@ -31,14 +25,14 @@ pub struct Config<'a> { } impl<'a> Config<'a> { - pub fn new(s: &str) -> Config { + pub fn new(s: &str) -> Config<'_> { let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); let default_dirs = vec![root.join("templates")]; let mut syntaxes = BTreeMap::new(); syntaxes.insert(DEFAULT_SYNTAX_NAME.to_string(), Syntax::default()); - let raw: RawConfig = + let raw: RawConfig<'_> = toml::from_str(&s).expect(&format!("invalid TOML in {}", CONFIG_FILE_NAME)); let (dirs, default_syntax) = match raw.general { -- cgit