aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-12-18 11:55:10 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-12-18 12:01:35 +0100
commit27b9ce2a00db1279e3d7ea3bc2dd39e3c54e72d1 (patch)
tree04ba9d50f83f429b2a319c460a728a88653dcfde
parent1b1ab5e1b94c136d3cd057f8214623a40e707e5f (diff)
downloadaskama-27b9ce2a00db1279e3d7ea3bc2dd39e3c54e72d1.tar.gz
askama-27b9ce2a00db1279e3d7ea3bc2dd39e3c54e72d1.tar.bz2
askama-27b9ce2a00db1279e3d7ea3bc2dd39e3c54e72d1.zip
Make API more idiomatic
-rw-r--r--askama_derive/src/config.rs6
-rw-r--r--askama_derive/src/lib.rs2
2 files changed, 4 insertions, 4 deletions
diff --git a/askama_derive/src/config.rs b/askama_derive/src/config.rs
index 2347f6c..b7959b1 100644
--- a/askama_derive/src/config.rs
+++ b/askama_derive/src/config.rs
@@ -21,7 +21,7 @@ pub(crate) struct Config<'a> {
impl<'a> Config<'a> {
pub(crate) fn new(
s: &'a str,
- template_whitespace: Option<&String>,
+ template_whitespace: Option<&str>,
) -> std::result::Result<Config<'a>, CompileError> {
let root = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let default_dirs = vec![root.join("templates")];
@@ -54,7 +54,7 @@ impl<'a> Config<'a> {
),
};
if let Some(template_whitespace) = template_whitespace {
- whitespace = match template_whitespace.as_str() {
+ whitespace = match template_whitespace {
"suppress" => WhitespaceHandling::Suppress,
"minimize" => WhitespaceHandling::Minimize,
"preserve" => WhitespaceHandling::Preserve,
@@ -636,7 +636,7 @@ mod tests {
#[test]
fn test_config_whitespace_error() {
- let config = Config::new(r#""#, Some(&"trim".to_owned()));
+ let config = Config::new(r#""#, Some("trim"));
if let Err(err) = config {
assert_eq!(err.msg, "invalid value for `whitespace`: \"trim\"");
} else {
diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs
index f9f3d41..65160c5 100644
--- a/askama_derive/src/lib.rs
+++ b/askama_derive/src/lib.rs
@@ -37,7 +37,7 @@ pub fn derive_template(input: TokenStream) -> TokenStream {
pub(crate) fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> {
let template_args = TemplateArgs::new(ast)?;
let toml = template_args.config()?;
- let config = Config::new(&toml, template_args.whitespace.as_ref())?;
+ let config = Config::new(&toml, template_args.whitespace.as_deref())?;
let input = TemplateInput::new(ast, &config, &template_args)?;
let mut templates = HashMap::new();