From 5ffe3de3115fe9d418a15e7813934e1fbe4ccd97 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 17 Oct 2018 01:56:30 -0700 Subject: Replace `format!()` with `to_string()` in filters --- askama_shared/src/filters/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'askama_shared') diff --git a/askama_shared/src/filters/mod.rs b/askama_shared/src/filters/mod.rs index 0efb7bc..3a58cc1 100644 --- a/askama_shared/src/filters/mod.rs +++ b/askama_shared/src/filters/mod.rs @@ -87,7 +87,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 { - let s = format!("{}", s); + let s = s.to_string(); let linebroken = s.replace("\n\n", "

").replace("\n", "
"); Ok(format!("

{}

", linebroken)) @@ -95,13 +95,13 @@ 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 { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.replace("\n", "
")) } /// Converts to lowercase pub fn lower(s: &fmt::Display) -> Result { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.to_lowercase()) } @@ -112,7 +112,7 @@ pub fn lowercase(s: &fmt::Display) -> Result { /// Converts to uppercase pub fn upper(s: &fmt::Display) -> Result { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.to_uppercase()) } @@ -123,13 +123,13 @@ pub fn uppercase(s: &fmt::Display) -> Result { /// Strip leading and trailing whitespace pub fn trim(s: &fmt::Display) -> Result { - let s = format!("{}", s); + 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 { - let mut s = format!("{}", s); + let mut s = s.to_string(); if s.len() < *len { Ok(s) } else { @@ -141,7 +141,7 @@ pub fn truncate(s: &fmt::Display, len: &usize) -> Result { /// Indent lines with `width` spaces pub fn indent(s: &fmt::Display, width: &usize) -> Result { - let s = format!("{}", s); + let s = s.to_string(); let mut indented = String::new(); @@ -190,7 +190,7 @@ where /// Capitalize a value. The first character will be uppercase, all others lowercase. pub fn capitalize(s: &fmt::Display) -> Result { - let mut s = format!("{}", s); + let mut s = s.to_string(); match s.get_mut(0..1).map(|s| { s.make_ascii_uppercase(); @@ -211,7 +211,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 { - let s = format!("{}", s); + let s = s.to_string(); let len = s.len(); if l <= len { @@ -238,7 +238,7 @@ pub fn center(s: &fmt::Display, l: usize) -> Result { /// Count the words in that string pub fn wordcount(s: &fmt::Display) -> Result { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.split_whitespace().count()) } -- cgit