diff --git a/CHANGELOG.md b/CHANGELOG.md index 090f23a..fc8db4c 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 + AsRef` 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..e9741d1 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -14,7 +14,6 @@ //! //! let files = Files::new(CACHE_BUSTER_DATA_FILE); //! ``` - use std::collections::HashMap; use serde::{Deserialize, Serialize}; @@ -40,8 +39,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 AsRef) -> Option<&'b str> { + if let Some(path) = self.map.get(path.as_ref()) { Some(&path[self.base_dir.len()..]) // Some(&path) } else { @@ -53,8 +52,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 AsRef) -> Option<&'b String> { + self.map.get(path.as_ref()) } }