3 use file_strategies::file::Strategy as FileStrategy;
4 use std::path::PathBuf;
6 pub struct FileHandler {
7 pub strategies: Vec<Box<dyn FileHandlerStrategy>>
10 impl Default for FileHandler {
11 fn default() -> FileHandler {
13 strategies: vec![Box::new(FileStrategy{})]
19 pub fn identify(&self, path: &PathBuf) -> FileType {
20 for strategy in self.strategies.iter() {
21 if strategy.is(&path) {
22 return strategy.identify();
28 pub fn handle(&self, path: &PathBuf) {
29 for strategy in self.strategies.iter() {
30 if strategy.can_handle(path) {
31 return strategy.handle(path);
37 pub trait FileHandlerStrategy {
38 fn is(&self, path: &PathBuf) -> bool;
39 fn identify(&self) -> FileType;
40 fn can_handle(&self, path: &PathBuf) -> bool;
41 fn handle(&self, path: &PathBuf);
53 pub file_type: FileType,