aboutsummaryrefslogtreecommitdiff
path: root/src/file_handler/mod.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <ruben@unlimited.pizza>2023-04-15 16:21:44 +0200
committerRuben Beltran del Rio <ruben@unlimited.pizza>2023-04-15 16:21:44 +0200
commit1e2d00b62ecce95f71d4bfd60a043c8e86631eee (patch)
tree96b78d90d01dd8d5765ac46cdad15eb783b3fdf0 /src/file_handler/mod.rs
parent8d4fac527ea33456de21933b4632a5bf4abbfc8d (diff)
Read the files
Diffstat (limited to 'src/file_handler/mod.rs')
-rw-r--r--src/file_handler/mod.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs
new file mode 100644
index 0000000..8038b3c
--- /dev/null
+++ b/src/file_handler/mod.rs
@@ -0,0 +1,54 @@
+mod file_strategies;
+
+use file_strategies::file::Strategy as FileStrategy;
+use std::path::PathBuf;
+
+pub struct FileHandler {
+ pub strategies: Vec<Box<dyn FileHandlerStrategy>>
+}
+
+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,
+}