X-Git-Url: https://git.r.bdr.sh/rbdr/page/blobdiff_plain/b03284133baa6339fe4adf48e4a6499ef3ac287b..3f1aa0b6eb90bd7912a63c6b72c2571486fbc21f:/src/file_handler/mod.rs?ds=sidebyside diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index 522bcbf..4e4bed9 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -8,7 +8,7 @@ use std::fs::read_to_string; use std::path::{Path, PathBuf}; pub struct FileHandler { - pub strategies: Vec>, + pub strategies: Vec>, pub layout: Option, } @@ -27,7 +27,7 @@ impl Default for FileHandler { impl FileHandler { pub fn identify(&self, path: &Path) -> FileType { - for strategy in self.strategies.iter() { + for strategy in &self.strategies { if strategy.is(path) { return strategy.identify(); } @@ -53,9 +53,9 @@ impl FileHandler { gemini_destination: &Path, files: &[File], ) { - files.iter().for_each(|file| { + for file in files { self.handle(source, html_destination, gemini_destination, file); - }); + } } pub fn handle( @@ -80,7 +80,7 @@ impl FileHandler { } } -pub trait FileHandlerStrategy { +pub trait Strategy { fn is(&self, path: &Path) -> bool; fn identify(&self) -> FileType; fn can_handle(&self, file_type: &FileType) -> bool; @@ -182,7 +182,7 @@ mod tests { file_type: FileType, } - impl FileHandlerStrategy for MockStrategy { + impl Strategy for MockStrategy { fn is(&self, _path: &Path) -> bool { self.is_match } @@ -208,11 +208,16 @@ mod tests { let handler = FileHandler { strategies: vec![Box::new(mock_strategy)], - layout: None, + layout: Some("None".to_string()), }; let path = PathBuf::from("test.whatever"); + let file = File{ + path: path.clone(), + file_type: FileType::Gemini + }; assert!(matches!(handler.identify(&path), FileType::Gemini)); + handler.handle(&path, &path, &path, &file); } #[test]