diff options
author | vallentin <mail@vallentin.dev> | 2021-03-09 06:38:56 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2021-03-10 13:09:56 +0100 |
commit | 7291494e6a79928cce6ae8844d6ec3092ce51663 (patch) | |
tree | 2535e58286c55000d185807a5e73d863522eab9c /askama_shared/src/input.rs | |
parent | 96a4328d642191e4925a8f822c9d2cf311f2f9ec (diff) | |
download | askama-7291494e6a79928cce6ae8844d6ec3092ce51663.tar.gz askama-7291494e6a79928cce6ae8844d6ec3092ce51663.tar.bz2 askama-7291494e6a79928cce6ae8844d6ec3092ce51663.zip |
Refactored getting path extension
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/input.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 59f1303..be380ea 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -1,6 +1,6 @@ use crate::{CompileError, Config, Syntax}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::str::FromStr; use quote::ToTokens; @@ -198,6 +198,14 @@ impl<'a> TemplateInput<'a> { path, }) } + + pub fn extension(&self) -> Option<&str> { + extension(&self.path) + } +} + +fn extension(path: &Path) -> Option<&str> { + path.extension().map(|s| s.to_str().unwrap()) } pub enum Source { |