make asset lookup generic over impl AsRef<&str>

This commit is contained in:
Aravinth Manivannan 2021-09-17 12:59:02 +05:30
parent 4435a569db
commit 1d91113524
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 7 additions and 5 deletions

View file

@ -21,6 +21,9 @@
is unset(i.e `None`), no mime based filtering is done and all files is unset(i.e `None`), no mime based filtering is done and all files
inside source directory is considered for processing. inside source directory is considered for processing.
- `Files::get_full_path()` and `Files::get()` now accept `impl
AsRef<str>` for path argument.
### Fixed: ### Fixed:
- `Files::get()` now behaves as it is described in the documentation - `Files::get()` now behaves as it is described in the documentation

View file

@ -14,7 +14,6 @@
//! //!
//! let files = Files::new(CACHE_BUSTER_DATA_FILE); //! let files = Files::new(CACHE_BUSTER_DATA_FILE);
//! ``` //! ```
use std::collections::HashMap; use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -40,8 +39,8 @@ impl Files {
/// ///
/// If the modified filename path is `./prod/test.randomhash.svg`, it will /// 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]. /// 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> { pub fn get<'a, 'b>(&'b self, path: impl AsRef<str>) -> Option<&'b str> {
if let Some(path) = self.map.get(path) { if let Some(path) = self.map.get(path.as_ref()) {
Some(&path[self.base_dir.len()..]) Some(&path[self.base_dir.len()..])
// Some(&path) // Some(&path)
} else { } else {
@ -53,8 +52,8 @@ impl Files {
/// ///
/// If the modified filename path is `./prod/test.randomhash.svg`, it will /// If the modified filename path is `./prod/test.randomhash.svg`, it will
/// output `/prod/test.randomhash.svg`. For relative path, see [get][Self::get]. /// 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> { pub fn get_full_path<'a, 'b>(&'b self, path: impl AsRef<str>) -> Option<&'b String> {
self.map.get(path) self.map.get(path.as_ref())
} }
} }