From e7fb11ecb9278b946fffd7e6c9f82c29e5b62c94 Mon Sep 17 00:00:00 2001 From: René Kijewski Date: Fri, 7 Jan 2022 01:15:40 +0100 Subject: Make TemplateInput::extension() reusable --- askama_shared/src/input.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'askama_shared/src') diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 25d61e1..a679461 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -193,11 +193,17 @@ impl TemplateInput<'_> { }) } + #[inline] pub fn extension(&self) -> Option<&str> { - self.ext.as_deref().or_else(|| extension(&self.path)) + ext_default_to_path(self.ext.as_deref(), &self.path) } } +#[inline] +pub fn ext_default_to_path<'a>(ext: Option<&'a str>, path: &'a Path) -> Option<&'a str> { + ext.or_else(|| extension(path)) +} + fn extension(path: &Path) -> Option<&str> { let ext = path.extension().map(|s| s.to_str().unwrap())?; -- cgit