mod file_strategies; use file_strategies::file::Strategy as FileStrategy; use std::path::PathBuf; pub struct FileHandler { pub strategies: Vec> } impl Default for FileHandler { fn default() -> FileHandler { FileHandler { strategies: vec![Box::new(FileStrategy{})] } } } impl FileHandler { pub fn identify(&self, path: &PathBuf) -> FileType { for strategy in self.strategies.iter() { if strategy.is(&path) { return strategy.identify(); } } FileType::Unknown } pub fn handle(&self, path: &PathBuf) { for strategy in self.strategies.iter() { if strategy.can_handle(path) { return strategy.handle(path); } } } } pub trait FileHandlerStrategy { fn is(&self, path: &PathBuf) -> bool; fn identify(&self) -> FileType; fn can_handle(&self, path: &PathBuf) -> bool; fn handle(&self, path: &PathBuf); } pub enum FileType { Gemini, File, Layout, Unknown, } pub struct File { pub path: PathBuf, pub file_type: FileType, }