diff options
author | Casey Rodarmor <casey@rodarmor.com> | 2018-10-17 01:56:30 -0700 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-10-17 11:14:27 +0200 |
commit | 5ffe3de3115fe9d418a15e7813934e1fbe4ccd97 (patch) | |
tree | d9f344387b761088d6f54d2557760b75a38c9334 /askama_shared | |
parent | 65e13033e14fc05230acb2e0f02cfa507ab2626d (diff) | |
download | askama-5ffe3de3115fe9d418a15e7813934e1fbe4ccd97.tar.gz askama-5ffe3de3115fe9d418a15e7813934e1fbe4ccd97.tar.bz2 askama-5ffe3de3115fe9d418a15e7813934e1fbe4ccd97.zip |
Replace `format!()` with `to_string()` in filters
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/filters/mod.rs | 20 |
1 files changed, 10 insertions, 10 deletions
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 `<br>` and a new line /// followed by a blank line becomes a paragraph break `<p>`. pub fn linebreaks(s: &fmt::Display) -> Result<String> { - let s = format!("{}", s); + let s = s.to_string(); let linebroken = s.replace("\n\n", "</p><p>").replace("\n", "<br/>"); Ok(format!("<p>{}</p>", linebroken)) @@ -95,13 +95,13 @@ pub fn linebreaks(s: &fmt::Display) -> Result<String> { /// Converts all newlines in a piece of plain text to HTML line breaks pub fn linebreaksbr(s: &fmt::Display) -> Result<String> { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.replace("\n", "<br/>")) } /// Converts to lowercase pub fn lower(s: &fmt::Display) -> Result<String> { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.to_lowercase()) } @@ -112,7 +112,7 @@ pub fn lowercase(s: &fmt::Display) -> Result<String> { /// Converts to uppercase pub fn upper(s: &fmt::Display) -> Result<String> { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.to_uppercase()) } @@ -123,13 +123,13 @@ pub fn uppercase(s: &fmt::Display) -> Result<String> { /// Strip leading and trailing whitespace pub fn trim(s: &fmt::Display) -> Result<String> { - 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<String> { - 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<String> { /// Indent lines with `width` spaces pub fn indent(s: &fmt::Display, width: &usize) -> Result<String> { - 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<String> { - 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<String> { /// Centers the value in a field of a given width pub fn center(s: &fmt::Display, l: usize) -> Result<String> { - 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<String> { /// Count the words in that string pub fn wordcount(s: &fmt::Display) -> Result<usize> { - let s = format!("{}", s); + let s = s.to_string(); Ok(s.split_whitespace().count()) } |