From c6d0a5cb2ed77f7b6e62a08c52e322467b038a58 Mon Sep 17 00:00:00 2001 From: lily Date: Sat, 29 Mar 2025 17:07:40 -0400 Subject: [PATCH] refac: use builder architecture --- src/lib.rs | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5c0694e..6b398fa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,11 +5,16 @@ use walkdir::{DirEntry, WalkDir}; mod tree; #[derive(Debug)] -pub struct KosmoraVfs { +pub struct KosmoraVfsBuilder { index: KosmoraIndex, packages: Vec, } +#[derive(Debug)] +pub struct KosmoraVfs { + builder: KosmoraVfsBuilder +} + #[derive(Debug)] struct KosmoraIndex { index: Vec, @@ -22,50 +27,62 @@ struct KosmoraPackage { } #[derive(Debug, Clone)] -pub enum KosmoraINodeType { +pub(crate) enum KosmoraINodeType { File(KosmoraFile), Directory(KosmoraDirectory), } #[derive(Debug, Clone)] -pub struct KosmoraFileMetadata { +pub(crate) struct KosmoraFileMetadata { name: String, extension: Option, size: usize, } #[derive(Debug, Clone)] -pub struct KosmoraFile { +pub(crate) struct KosmoraFile { metadata: KosmoraFileMetadata, data: Vec, } #[derive(Debug, Clone)] -pub struct KosmoraDirectory { +pub(crate) struct KosmoraDirectory { name: String, parent: Option>, children: Option>, } #[derive(Debug, Clone)] -pub struct KosmoraINode { +pub(crate) struct KosmoraINode { inode: KosmoraINodeType, } -impl KosmoraVfs { +impl KosmoraVfsBuilder { pub fn new() -> Self { - KosmoraVfs { - index: KosmoraIndex { index: Vec::new() }, - packages: Vec::new(), + KosmoraVfsBuilder { + index: KosmoraIndex { index: vec![] }, + packages: vec![], } } - pub fn create_directory(virtual_path: &str) {} - pub fn add_directory(real_path: &str, virtual_path: &str) {} - pub fn add_file(real_path: &str, virtual_path: &str) {} + pub fn new_directory(&mut self, virtual_path: &str) -> Self { + todo!() + } + + pub fn add_directory(&mut self, physical_path: &str, virtual_path: &str) -> Self { + todo!() + } + + pub fn add_file(&mut self, physical_path: &str, virtual_path: &str) -> Self { + todo!() + } + + pub fn build(&mut self) { + todo!() + } } -pub trait KosmoraINodeInteroperable { +pub(crate) trait KosmoraINodeInteroperable { fn collect_directory_children(&self) -> Vec; fn to_kosmora_inode(&self) -> KosmoraINode; fn to_kosmora_directory(&self) -> KosmoraDirectory;