3 use file_strategies::file::Strategy as FileStrategy;
4 use file_strategies::gemini::Strategy as GeminiStrategy;
5 use file_strategies::layout::Strategy as LayoutStrategy;
7 use std::path::PathBuf;
9 pub struct FileHandler {
10 pub strategies: Vec<Box<dyn FileHandlerStrategy>>
13 impl Default for FileHandler {
14 fn default() -> FileHandler {
17 Box::new(GeminiStrategy{}),
18 Box::new(LayoutStrategy{}),
19 Box::new(FileStrategy{}),
26 pub fn identify(&self, path: &PathBuf) -> FileType {
27 for strategy in self.strategies.iter() {
28 if strategy.is(&path) {
29 return strategy.identify();
35 pub fn handle(&self, path: &PathBuf) {
36 for strategy in self.strategies.iter() {
37 if strategy.can_handle(path) {
38 return strategy.handle(path);
44 pub trait FileHandlerStrategy {
45 fn is(&self, path: &PathBuf) -> bool;
46 fn identify(&self) -> FileType;
47 fn can_handle(&self, path: &PathBuf) -> bool;
48 fn handle(&self, path: &PathBuf);
60 pub file_type: FileType,