diff --git a/backend/src/generator.rs b/backend/src/generator.rs index c8cf6c2..a19ad0e 100644 --- a/backend/src/generator.rs +++ b/backend/src/generator.rs @@ -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(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result, - gen: impl Fn(&PathBuf) -> Result<()>) -> Result; - fn get_cached_json(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result) -> Result - where T: de::DeserializeOwned + ?Sized + ser::Serialize; - fn get_mime(&self, file: &PathBuf) -> Result; -} - -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(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result, + pub fn get_cached(&self, file: &PathBuf, token: &str, read: impl Fn(&PathBuf) -> Result, gen: impl Fn(&PathBuf) -> Result<()>) -> Result { 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(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result) -> Result + pub fn get_cached_json(&self, file: &PathBuf, token: &str, gen: impl Fn() -> Result) -> Result 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 { + pub fn get_mime(&self, file: &PathBuf) -> Result { self.get_cached(&file, "mime", |f| { Ok(fs::read_to_string(f)?) }, |f| {