[-] Remove explicit trait

This commit is contained in:
Azalea Gui
2023-02-23 12:24:01 -05:00
parent 025d3922e7
commit 63e9fd7e95
+7 -16
View File
@@ -1,3 +1,4 @@
use crate::macros::*;
use crate::utils::*;
@@ -26,28 +27,18 @@ pub struct Generator {
pub(crate) base: PathBuf,
}
pub trait GeneratorTraits {
fn new(base: PathBuf) -> Generator;
fn dot_path(&self, path: &PathBuf) -> PathBuf;
fn get_cached<T>(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result<T>,
gen: impl Fn(&PathBuf) -> Result<()>) -> Result<T>;
fn get_cached_json<T>(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result<T>) -> Result<T>
where T: de::DeserializeOwned + ?Sized + ser::Serialize;
fn get_mime(&self, file: &PathBuf) -> Result<String>;
}
impl GeneratorTraits for Generator {
fn new(base: PathBuf) -> Generator {
impl Generator {
pub fn new(base: PathBuf) -> Generator {
Generator { mime_db: SharedMimeInfo::new(), base }
}
/// Get the same file location in DOT_PATH directory
fn dot_path(&self, path: &PathBuf) -> PathBuf {
pub fn dot_path(&self, path: &PathBuf) -> PathBuf {
self.base.join(DOT_PATH).join(diff_paths(&path, &self.base).unwrap())
}
/// Get the cached result
fn get_cached<T>(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result<T>,
pub fn get_cached<T>(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result<T>,
gen: impl Fn(&PathBuf) -> Result<()>) -> Result<T> {
let dot = self.dot_path(file).with_extension(token);
if ! dot.exists() || match (dot.metadata(), file.metadata()) {
@@ -61,7 +52,7 @@ impl GeneratorTraits for Generator {
}
/// Get the cached result
fn get_cached_json<T>(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result<T>) -> Result<T>
pub fn get_cached_json<T>(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result<T>) -> Result<T>
where T: de::DeserializeOwned + ?Sized + ser::Serialize {
self.get_cached(&file, token, |f| {
let open = File::open(f)?;
@@ -76,7 +67,7 @@ impl GeneratorTraits for Generator {
}
/// Get cached mime type
fn get_mime(&self, file: &PathBuf) -> Result<String> {
pub fn get_mime(&self, file: &PathBuf) -> Result<String> {
self.get_cached(&file, "mime", |f| {
Ok(fs::read_to_string(f)?)
}, |f| {