From 978d99b0848e1d7cf279fe28c6dc707e59e9906c Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 17 Sep 2021 12:59:02 +0530 Subject: [PATCH] make asset lookup generic over impl Into<&str> --- CHANGELOG.md | 3 +++ src/filemap.rs | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 090f23a..7aae4ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ is unset(i.e `None`), no mime based filtering is done and all files inside source directory is considered for processing. +- `Files::get_full_path()` and `Files::get()` now accept `impl + Into<&str>` for path argument. + ### Fixed: - `Files::get()` now behaves as it is described in the documentation diff --git a/src/filemap.rs b/src/filemap.rs index 30cbc9d..bd29053 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -40,8 +40,8 @@ impl Files { /// /// If the modified filename path is `./prod/test.randomhash.svg`, it will /// output `/test.randomhash.svg`. For full path, see [get_full_path][Self::get_full_path]. - pub fn get<'a>(&'a self, path: &'a str) -> Option<&'a str> { - if let Some(path) = self.map.get(path) { + pub fn get<'a, 'b>(&'b self, path: impl Into<&'a str>) -> Option<&'b str> { + if let Some(path) = self.map.get(path.into()) { Some(&path[self.base_dir.len()..]) // Some(&path) } else { @@ -53,8 +53,8 @@ impl Files { /// /// If the modified filename path is `./prod/test.randomhash.svg`, it will /// output `/prod/test.randomhash.svg`. For relative path, see [get][Self::get]. - pub fn get_full_path<'a>(&'a self, path: &'a str) -> Option<&'a String> { - self.map.get(path) + pub fn get_full_path<'a, 'b>(&'b self, path: impl Into<&'a str>) -> Option<&'b String> { + self.map.get(path.into()) } }