aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar René Kijewski <kijewski@library.vetmed.fu-berlin.de>2022-01-07 01:15:40 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2022-01-07 13:18:03 +0100
commite7fb11ecb9278b946fffd7e6c9f82c29e5b62c94 (patch)
tree5d23ba78c0993112c6a902232043778b2253dfe7
parenteff10b74567881eef73868f3e3391c6a0e922375 (diff)
downloadaskama-e7fb11ecb9278b946fffd7e6c9f82c29e5b62c94.tar.gz
askama-e7fb11ecb9278b946fffd7e6c9f82c29e5b62c94.tar.bz2
askama-e7fb11ecb9278b946fffd7e6c9f82c29e5b62c94.zip
Make TemplateInput::extension() reusable
-rw-r--r--askama_shared/src/input.rs8
1 files changed, 7 insertions, 1 deletions
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())?;