Apply clippy suggestions for 1.67 (#769)

This commit is contained in:
Dirkjan Ochtman 2023-01-30 09:51:23 +01:00 committed by GitHub
parent 23326b4765
commit 3003d86264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 82 additions and 74 deletions

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "../README.md" readme = "../README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }

View File

@ -56,10 +56,10 @@ impl std::error::Error for Error {
impl Display 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 { match self {
Error::Fmt(err) => write!(formatter, "formatting error: {}", err), Error::Fmt(err) => write!(formatter, "formatting error: {err}"),
Error::Custom(err) => write!(formatter, "{}", err), Error::Custom(err) => write!(formatter, "{err}"),
#[cfg(feature = "serde_json")] #[cfg(feature = "serde_json")]
Error::Json(err) => write!(formatter, "json conversion error: {}", err), Error::Json(err) => write!(formatter, "json conversion error: {err}"),
#[cfg(feature = "serde_yaml")] #[cfg(feature = "serde_yaml")]
Error::Yaml(err) => write!(formatter, "yaml conversion error: {}", err), Error::Yaml(err) => write!(formatter, "yaml conversion error: {}", err),
} }

View File

@ -163,7 +163,7 @@ pub fn linebreaks<T: fmt::Display>(s: T) -> Result<String> {
let s = s.to_string(); let s = s.to_string();
let linebroken = s.replace("\n\n", "</p><p>").replace('\n', "<br/>"); let linebroken = s.replace("\n\n", "</p><p>").replace('\n', "<br/>");
Ok(format!("<p>{}</p>", linebroken)) Ok(format!("<p>{linebroken}</p>"))
} }
/// Converts all newlines in a piece of plain text to HTML line breaks /// Converts all newlines in a piece of plain text to HTML line breaks
@ -181,7 +181,7 @@ pub fn paragraphbreaks<T: fmt::Display>(s: T) -> Result<String> {
let s = s.to_string(); let s = s.to_string();
let linebroken = s.replace("\n\n", "</p><p>").replace("<p></p>", ""); let linebroken = s.replace("\n\n", "</p><p>").replace("<p></p>", "");
Ok(format!("<p>{}</p>", linebroken)) Ok(format!("<p>{linebroken}</p>"))
} }
/// Converts to lowercase /// Converts to lowercase
@ -279,7 +279,7 @@ where
rv.push_str(separator); rv.push_str(separator);
} }
write!(rv, "{}", item)?; write!(rv, "{item}")?;
} }
Ok(rv) Ok(rv)

View File

@ -93,7 +93,7 @@ pub trait Template: fmt::Display {
/// Renders the template to the given `writer` io buffer /// Renders the template to the given `writer` io buffer
#[inline] #[inline]
fn write_into(&self, writer: &mut (impl std::io::Write + ?Sized)) -> std::io::Result<()> { fn write_into(&self, writer: &mut (impl std::io::Write + ?Sized)) -> std::io::Result<()> {
writer.write_fmt(format_args!("{}", self)) writer.write_fmt(format_args!("{self}"))
} }
/// The template's extension, if provided /// The template's extension, if provided
@ -140,7 +140,7 @@ impl<T: Template> DynTemplate for T {
#[inline] #[inline]
fn dyn_write_into(&self, writer: &mut dyn std::io::Write) -> std::io::Result<()> { fn dyn_write_into(&self, writer: &mut dyn std::io::Write) -> std::io::Result<()> {
writer.write_fmt(format_args!("{}", self)) writer.write_fmt(format_args!("{self}"))
} }
fn extension(&self) -> Option<&'static str> { fn extension(&self) -> Option<&'static str> {
@ -201,7 +201,7 @@ mod tests {
assert_eq!(test.to_string(), "test"); assert_eq!(test.to_string(), "test");
assert_eq!(format!("{}", test), "test"); assert_eq!(format!("{test}"), "test");
let mut vec = Vec::new(); let mut vec = Vec::new();
test.dyn_write_into(&mut vec).unwrap(); test.dyn_write_into(&mut vec).unwrap();

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
actix-web = { version = "4", default-features = false } actix-web = { version = "4", default-features = false }

View File

@ -1,7 +1,8 @@
[package] [package]
name = "askama_axum" name = "askama_axum"
version = "0.1.0" version = "0.1.0"
edition = "2018" edition = "2021"
rust-version = "1.58"
description = "Axum integration for Askama templates" description = "Axum integration for Askama templates"
keywords = ["markup", "template", "jinja2", "html", "axum"] keywords = ["markup", "template", "jinja2", "html", "axum"]
categories = ["template-engine"] categories = ["template-engine"]

View File

@ -7,7 +7,8 @@ repository = "https://github.com/djc/askama"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[lib] [lib]
proc-macro = true proc-macro = true

View File

@ -1,5 +1,4 @@
use std::collections::{BTreeMap, HashSet}; use std::collections::{BTreeMap, HashSet};
use std::convert::TryFrom;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::{env, fs}; use std::{env, fs};
@ -58,13 +57,13 @@ impl Config<'_> {
.insert(name.to_string(), Syntax::try_from(raw_s)?) .insert(name.to_string(), Syntax::try_from(raw_s)?)
.is_some() .is_some()
{ {
return Err(format!("syntax \"{}\" is already defined", name).into()); return Err(format!("syntax \"{name}\" is already defined").into());
} }
} }
} }
if !syntaxes.contains_key(default_syntax) { if !syntaxes.contains_key(default_syntax) {
return Err(format!("default syntax \"{}\" not found", default_syntax).into()); return Err(format!("default syntax \"{default_syntax}\" not found").into());
} }
let mut escapers = Vec::new(); let mut escapers = Vec::new();
@ -193,7 +192,7 @@ struct RawConfig<'d> {
impl RawConfig<'_> { impl RawConfig<'_> {
#[cfg(feature = "config")] #[cfg(feature = "config")]
fn from_toml_str(s: &str) -> std::result::Result<RawConfig<'_>, CompileError> { fn from_toml_str(s: &str) -> std::result::Result<RawConfig<'_>, CompileError> {
toml::from_str(s).map_err(|e| format!("invalid TOML in {}: {}", CONFIG_FILE_NAME, e).into()) toml::from_str(s).map_err(|e| format!("invalid TOML in {CONFIG_FILE_NAME}: {e}").into())
} }
#[cfg(not(feature = "config"))] #[cfg(not(feature = "config"))]

View File

@ -70,7 +70,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
) )
.build(&contexts[input.path.as_path()])?; .build(&contexts[input.path.as_path()])?;
if input.print == Print::Code || input.print == Print::All { if input.print == Print::Code || input.print == Print::All {
eprintln!("{}", code); eprintln!("{code}");
} }
Ok(code) Ok(code)
} }
@ -106,7 +106,7 @@ impl TemplateArgs {
template_args = Some(nested); template_args = Some(nested);
} }
Ok(_) => return Err("'template' attribute must be a list".into()), Ok(_) => return Err("'template' attribute must be a list".into()),
Err(e) => return Err(format!("unable to parse attribute: {}", e).into()), Err(e) => return Err(format!("unable to parse attribute: {e}").into()),
} }
} }
} }
@ -182,7 +182,7 @@ impl TemplateArgs {
return Err("config value must be string literal".into()); return Err("config value must be string literal".into());
} }
} else { } else {
return Err(format!("unsupported attribute key {:?} found", ident).into()); return Err(format!("unsupported attribute key {ident:?} found").into());
} }
} }
@ -362,7 +362,7 @@ impl<'a> Generator<'a> {
buf.writeln(";")?; buf.writeln(";")?;
buf.writeln("const SIZE_HINT: ::std::primitive::usize = ")?; buf.writeln("const SIZE_HINT: ::std::primitive::usize = ")?;
buf.writeln(&format!("{}", size_hint))?; buf.writeln(&format!("{size_hint}"))?;
buf.writeln(";")?; buf.writeln(";")?;
buf.writeln("const MIME_TYPE: &'static ::std::primitive::str = ")?; buf.writeln("const MIME_TYPE: &'static ::std::primitive::str = ")?;
@ -755,7 +755,7 @@ impl<'a> Generator<'a> {
let mut arm_sizes = Vec::new(); let mut arm_sizes = Vec::new();
let expr_code = self.visit_expr_root(expr)?; let expr_code = self.visit_expr_root(expr)?;
buf.writeln(&format!("match &{} {{", expr_code))?; buf.writeln(&format!("match &{expr_code} {{"))?;
let mut arm_size = 0; let mut arm_size = 0;
for (i, arm) in arms.iter().enumerate() { for (i, arm) in arms.iter().enumerate() {
@ -802,24 +802,24 @@ impl<'a> Generator<'a> {
buf.writeln("{")?; buf.writeln("{")?;
buf.writeln("let mut _did_loop = false;")?; buf.writeln("let mut _did_loop = false;")?;
match loop_block.iter { match loop_block.iter {
Expr::Range(_, _, _) => buf.writeln(&format!("let _iter = {};", expr_code)), Expr::Range(_, _, _) => buf.writeln(&format!("let _iter = {expr_code};")),
Expr::Array(..) => buf.writeln(&format!("let _iter = {}.iter();", expr_code)), Expr::Array(..) => buf.writeln(&format!("let _iter = {expr_code}.iter();")),
// If `iter` is a call then we assume it's something that returns // If `iter` is a call then we assume it's something that returns
// an iterator. If not then the user can explicitly add the needed // an iterator. If not then the user can explicitly add the needed
// call without issues. // call without issues.
Expr::Call(..) | Expr::Index(..) => { Expr::Call(..) | Expr::Index(..) => {
buf.writeln(&format!("let _iter = ({}).into_iter();", expr_code)) buf.writeln(&format!("let _iter = ({expr_code}).into_iter();"))
} }
// If accessing `self` then it most likely needs to be // If accessing `self` then it most likely needs to be
// borrowed, to prevent an attempt of moving. // borrowed, to prevent an attempt of moving.
_ if expr_code.starts_with("self.") => { _ if expr_code.starts_with("self.") => {
buf.writeln(&format!("let _iter = (&{}).into_iter();", expr_code)) buf.writeln(&format!("let _iter = (&{expr_code}).into_iter();"))
} }
// If accessing a field then it most likely needs to be // If accessing a field then it most likely needs to be
// borrowed, to prevent an attempt of moving. // borrowed, to prevent an attempt of moving.
Expr::Attr(..) => buf.writeln(&format!("let _iter = (&{}).into_iter();", expr_code)), Expr::Attr(..) => buf.writeln(&format!("let _iter = (&{expr_code}).into_iter();")),
// Otherwise, we borrow `iter` assuming that it implements `IntoIterator`. // Otherwise, we borrow `iter` assuming that it implements `IntoIterator`.
_ => buf.writeln(&format!("let _iter = ({}).into_iter();", expr_code)), _ => buf.writeln(&format!("let _iter = ({expr_code}).into_iter();")),
}?; }?;
if let Some(cond) = &loop_block.cond { if let Some(cond) = &loop_block.cond {
self.locals.push(); self.locals.push();
@ -872,13 +872,14 @@ impl<'a> Generator<'a> {
let (def, own_ctx) = match scope { let (def, own_ctx) = match scope {
Some(s) => { Some(s) => {
let path = ctx.imports.get(s).ok_or_else(|| { let path = ctx.imports.get(s).ok_or_else(|| {
CompileError::from(format!("no import found for scope {:?}", s)) CompileError::from(format!("no import found for scope {s:?}"))
})?;
let mctx = self.contexts.get(path.as_path()).ok_or_else(|| {
CompileError::from(format!("context for {:?} not found", path))
})?; })?;
let mctx = self
.contexts
.get(path.as_path())
.ok_or_else(|| CompileError::from(format!("context for {path:?} not found")))?;
let def = mctx.macros.get(name).ok_or_else(|| { let def = mctx.macros.get(name).ok_or_else(|| {
CompileError::from(format!("macro {:?} not found in scope {:?}", name, s)) CompileError::from(format!("macro {name:?} not found in scope {s:?}"))
})?; })?;
(def, mctx) (def, mctx)
} }
@ -886,7 +887,7 @@ impl<'a> Generator<'a> {
let def = ctx let def = ctx
.macros .macros
.get(name) .get(name)
.ok_or_else(|| CompileError::from(format!("macro {:?} not found", name)))?; .ok_or_else(|| CompileError::from(format!("macro {name:?} not found")))?;
(def, ctx) (def, ctx)
} }
}; };
@ -902,7 +903,7 @@ impl<'a> Generator<'a> {
let mut is_first_variable = true; let mut is_first_variable = true;
for (i, arg) in def.args.iter().enumerate() { for (i, arg) in def.args.iter().enumerate() {
let expr = args.get(i).ok_or_else(|| { let expr = args.get(i).ok_or_else(|| {
CompileError::from(format!("macro {:?} takes more than {} arguments", name, i)) CompileError::from(format!("macro {name:?} takes more than {i} arguments"))
})?; })?;
match expr { match expr {
@ -1089,7 +1090,7 @@ impl<'a> Generator<'a> {
(Some(cur_name), None) => (cur_name, 0), (Some(cur_name), None) => (cur_name, 0),
// A block definition contains a block definition of the same name // A block definition contains a block definition of the same name
(Some(cur_name), Some((prev_name, _))) if cur_name == prev_name => { (Some(cur_name), Some((prev_name, _))) if cur_name == prev_name => {
return Err(format!("cannot define recursive blocks ({})", cur_name).into()); return Err(format!("cannot define recursive blocks ({cur_name})").into());
} }
// A block definition contains a definition of another block // A block definition contains a definition of another block
(Some(cur_name), Some((_, _))) => (cur_name, 0), (Some(cur_name), Some((_, _))) => (cur_name, 0),
@ -1108,7 +1109,7 @@ impl<'a> Generator<'a> {
let (ctx, def) = heritage.blocks[cur.0].get(cur.1).ok_or_else(|| { let (ctx, def) = heritage.blocks[cur.0].get(cur.1).ok_or_else(|| {
CompileError::from(match name { CompileError::from(match name {
None => format!("no super() block found for block '{}'", cur.0), None => format!("no super() block found for block '{}'", cur.0),
Some(name) => format!("no block found for name '{}'", name), Some(name) => format!("no block found for name '{name}'"),
}) })
})?; })?;
@ -1193,7 +1194,7 @@ impl<'a> Generator<'a> {
let id = self.named; let id = self.named;
self.named += 1; self.named += 1;
buf_expr.write(&format!("expr{} = ", id)); buf_expr.write(&format!("expr{id} = "));
buf_expr.write("&"); buf_expr.write("&");
buf_expr.write(&expression); buf_expr.write(&expression);
buf_expr.writeln(",")?; buf_expr.writeln(",")?;
@ -1206,7 +1207,7 @@ impl<'a> Generator<'a> {
} }
}; };
buf_format.write(&format!("{{expr{}}}", id)); buf_format.write(&format!("{{expr{id}}}"));
size_hint += 3; size_hint += 3;
} }
} }
@ -1395,9 +1396,9 @@ impl<'a> Generator<'a> {
name, self.input.escaper name, self.input.escaper
)); ));
} else if crate::BUILT_IN_FILTERS.contains(&name) { } else if crate::BUILT_IN_FILTERS.contains(&name) {
buf.write(&format!("::askama::filters::{}(", name)); buf.write(&format!("::askama::filters::{name}("));
} else { } else {
buf.write(&format!("filters::{}(", name)); buf.write(&format!("filters::{name}("));
} }
self._visit_args(buf, args)?; self._visit_args(buf, args)?;
@ -1601,7 +1602,7 @@ impl<'a> Generator<'a> {
} }
_ => return Err("loop.cycle(…) expects exactly one argument".into()), _ => return Err("loop.cycle(…) expects exactly one argument".into()),
}, },
s => return Err(format!("unknown loop method: {:?}", s).into()), s => return Err(format!("unknown loop method: {s:?}").into()),
}, },
left => { left => {
match left { match left {
@ -1658,7 +1659,7 @@ impl<'a> Generator<'a> {
right: &Expr<'_>, right: &Expr<'_>,
) -> Result<DisplayWrap, CompileError> { ) -> Result<DisplayWrap, CompileError> {
self.visit_expr(buf, left)?; self.visit_expr(buf, left)?;
buf.write(&format!(" {} ", op)); buf.write(&format!(" {op} "));
self.visit_expr(buf, right)?; self.visit_expr(buf, right)?;
Ok(DisplayWrap::Unwrapped) Ok(DisplayWrap::Unwrapped)
} }
@ -1733,12 +1734,12 @@ impl<'a> Generator<'a> {
} }
fn visit_str_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { fn visit_str_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap {
buf.write(&format!("\"{}\"", s)); buf.write(&format!("\"{s}\""));
DisplayWrap::Unwrapped DisplayWrap::Unwrapped
} }
fn visit_char_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { fn visit_char_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap {
buf.write(&format!("'{}'", s)); buf.write(&format!("'{s}'"));
DisplayWrap::Unwrapped DisplayWrap::Unwrapped
} }
@ -2032,8 +2033,7 @@ impl MapChain<'_, &str, LocalMeta> {
fn resolve_or_self(&self, name: &str) -> String { fn resolve_or_self(&self, name: &str) -> String {
let name = normalize_identifier(name); let name = normalize_identifier(name);
self.resolve(name) self.resolve(name).unwrap_or_else(|| format!("self.{name}"))
.unwrap_or_else(|| format!("self.{}", name))
} }
} }

View File

@ -42,7 +42,7 @@ impl TemplateInput<'_> {
// of `ext` is merged into a synthetic `path` value here. // of `ext` is merged into a synthetic `path` value here.
let source = source.expect("template path or source not found in attributes"); let source = source.expect("template path or source not found in attributes");
let path = match (&source, &ext) { let path = match (&source, &ext) {
(&Source::Path(ref path), _) => config.find_template(path, None)?, (Source::Path(path), _) => config.find_template(path, None)?,
(&Source::Source(_), Some(ext)) => PathBuf::from(format!("{}.{}", ast.ident, ext)), (&Source::Source(_), Some(ext)) => PathBuf::from(format!("{}.{}", ast.ident, ext)),
(&Source::Source(_), None) => { (&Source::Source(_), None) => {
return Err("must include 'ext' attribute when using 'source' attribute".into()) return Err("must include 'ext' attribute when using 'source' attribute".into())
@ -56,7 +56,7 @@ impl TemplateInput<'_> {
config config
.syntaxes .syntaxes
.get(&s) .get(&s)
.ok_or_else(|| CompileError::from(format!("attribute syntax {} not exist", s))) .ok_or_else(|| CompileError::from(format!("attribute syntax {s} not exist")))
}, },
)?; )?;
@ -78,7 +78,7 @@ impl TemplateInput<'_> {
} }
let escaper = escaper.ok_or_else(|| { let escaper = escaper.ok_or_else(|| {
CompileError::from(format!("no escaper defined for extension '{}'", escaping)) CompileError::from(format!("no escaper defined for extension '{escaping}'"))
})?; })?;
let mime_type = let mime_type =
@ -146,7 +146,7 @@ impl FromStr for Print {
"ast" => Ast, "ast" => Ast,
"code" => Code, "code" => Code,
"none" => None, "none" => None,
v => return Err(format!("invalid value for print option: {}", v,).into()), v => return Err(format!("invalid value for print option: {v}",).into()),
}) })
} }
} }

View File

@ -1238,7 +1238,7 @@ pub(crate) fn parse<'a>(
match parse_template(src, &state) { match parse_template(src, &state) {
Ok((left, res)) => { Ok((left, res)) => {
if !left.is_empty() { if !left.is_empty() {
Err(format!("unable to parse template:\n\n{:?}", left).into()) Err(format!("unable to parse template:\n\n{left:?}").into())
} else { } else {
Ok(res) Ok(res)
} }
@ -1251,7 +1251,7 @@ pub(crate) fn parse<'a>(
let source_after = match source_after.char_indices().enumerate().take(41).last() { let source_after = match source_after.char_indices().enumerate().take(41).last() {
Some((40, (i, _))) => format!("{:?}...", &source_after[..i]), Some((40, (i, _))) => format!("{:?}...", &source_after[..i]),
_ => format!("{:?}", source_after), _ => format!("{source_after:?}"),
}; };
let (row, last_line) = source_before.lines().enumerate().last().unwrap(); let (row, last_line) = source_before.lines().enumerate().last().unwrap();

View File

@ -9,7 +9,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[badges] [badges]
maintenance = { status = "actively-developed" } maintenance = { status = "actively-developed" }

View File

@ -56,8 +56,7 @@ where
fmt, fmt,
escaper: &self.escaper escaper: &self.escaper
}, },
"{}", "{t}"
t
), ),
DisplayValue::Safe(ref t) => t.fmt(fmt), DisplayValue::Safe(ref t) => t.fmt(fmt),
} }

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-gotham", "mime", "mime_guess"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-gotham", "mime", "mime_guess"] }

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-hyper"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-hyper"] }

View File

@ -43,7 +43,7 @@ async fn test_hyper() {
server.await.expect("Could not serve"); server.await.expect("Could not serve");
}; };
let query = async move { let query = async move {
let uri = format!("http://{}/hello/world", local_addr) let uri = format!("http://{local_addr}/hello/world")
.parse() .parse()
.expect("Could not format URI"); .expect("Could not format URI");
let client = Client::new(); let client = Client::new();

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-mendes", "mime", "mime_guess"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-mendes", "mime", "mime_guess"] }

View File

@ -71,8 +71,8 @@ impl From<mendes::Error> for Error {
impl std::fmt::Display for Error { impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self { match self {
Error::Askama(e) => write!(f, "{}", e), Error::Askama(e) => write!(f, "{e}"),
Error::Mendes(e) => write!(f, "{}", e), Error::Mendes(e) => write!(f, "{e}"),
} }
} }
} }

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-rocket", "mime", "mime_guess"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-rocket", "mime", "mime_guess"] }

View File

@ -1,7 +1,8 @@
[package] [package]
name = "askama_tide" name = "askama_tide"
version = "0.14.0" version = "0.14.0"
edition = "2018" edition = "2021"
rust-version = "1.58"
description = "Tide integration for Askama templates" description = "Tide integration for Askama templates"
keywords = ["markup", "template", "html", "tide", "http-types"] keywords = ["markup", "template", "html", "tide", "http-types"]
homepage = "https://github.com/djc/askama" homepage = "https://github.com/djc/askama"

View File

@ -1,6 +1,5 @@
use askama::Template; use askama::Template;
use async_std::prelude::*; use async_std::prelude::*;
use std::convert::TryInto;
use tide::{http::mime::HTML, Body, Response}; use tide::{http::mime::HTML, Body, Response};
#[derive(Template)] #[derive(Template)]

View File

@ -10,7 +10,8 @@ repository = "https://github.com/djc/askama"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
workspace = ".." workspace = ".."
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2021"
rust-version = "1.58"
[dependencies] [dependencies]
askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-warp", "mime", "mime_guess"] } askama = { version = "0.11.2", path = "../askama", default-features = false, features = ["with-warp", "mime", "mime_guess"] }

View File

@ -3,7 +3,8 @@ name = "askama_testing"
version = "0.1.0" version = "0.1.0"
authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"] authors = ["Dirkjan Ochtman <dirkjan@ochtman.nl>"]
workspace = ".." workspace = ".."
edition = "2018" edition = "2021"
rust-version = "1.58"
publish = false publish = false
[features] [features]

View File

@ -122,8 +122,7 @@ mod filters {
} }
// for test_nested_filter_ref // for test_nested_filter_ref
pub fn mytrim(s: &dyn (::std::fmt::Display)) -> ::askama::Result<String> { pub fn mytrim(s: &dyn (::std::fmt::Display)) -> ::askama::Result<String> {
let s = format!("{}", s); Ok(s.to_string().trim().to_owned())
Ok(s.trim().to_owned())
} }
} }

View File

@ -311,14 +311,14 @@ struct FunctionRefTemplate {
#[test] #[test]
fn test_func_ref_call() { fn test_func_ref_call() {
let t = FunctionRefTemplate { let t = FunctionRefTemplate {
world: |s, r| format!("world({}, {})", s, r), world: |s, r| format!("world({s}, {r})"),
}; };
assert_eq!(t.render().unwrap(), "Hello, world(123, 4)!"); assert_eq!(t.render().unwrap(), "Hello, world(123, 4)!");
} }
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
fn world2(s: &str, v: u8) -> String { fn world2(s: &str, v: u8) -> String {
format!("world{}{}", v, s) format!("world{v}{s}")
} }
#[derive(Template)] #[derive(Template)]
@ -346,7 +346,7 @@ struct FunctionTemplate;
impl FunctionTemplate { impl FunctionTemplate {
#[allow(clippy::trivially_copy_pass_by_ref)] #[allow(clippy::trivially_copy_pass_by_ref)]
fn world3(&self, s: &str, v: u8) -> String { fn world3(&self, s: &str, v: u8) -> String {
format!("world{}{}", s, v) format!("world{s}{v}")
} }
} }