refac: use builder architecture

This commit is contained in:
lily 2025-03-29 17:07:40 -04:00
parent 16b505f5cf
commit c6d0a5cb2e
Signed by: lily
GPG key ID: 601F3263FBCBC4B9

View file

@ -5,11 +5,16 @@ use walkdir::{DirEntry, WalkDir};
mod tree; mod tree;
#[derive(Debug)] #[derive(Debug)]
pub struct KosmoraVfs { pub struct KosmoraVfsBuilder {
index: KosmoraIndex, index: KosmoraIndex,
packages: Vec<KosmoraPackage>, packages: Vec<KosmoraPackage>,
} }
#[derive(Debug)]
pub struct KosmoraVfs {
builder: KosmoraVfsBuilder
}
#[derive(Debug)] #[derive(Debug)]
struct KosmoraIndex { struct KosmoraIndex {
index: Vec<KosmoraPackage>, index: Vec<KosmoraPackage>,
@ -22,50 +27,62 @@ struct KosmoraPackage {
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum KosmoraINodeType { pub(crate) enum KosmoraINodeType {
File(KosmoraFile), File(KosmoraFile),
Directory(KosmoraDirectory), Directory(KosmoraDirectory),
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KosmoraFileMetadata { pub(crate) struct KosmoraFileMetadata {
name: String, name: String,
extension: Option<String>, extension: Option<String>,
size: usize, size: usize,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KosmoraFile { pub(crate) struct KosmoraFile {
metadata: KosmoraFileMetadata, metadata: KosmoraFileMetadata,
data: Vec<u8>, data: Vec<u8>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KosmoraDirectory { pub(crate) struct KosmoraDirectory {
name: String, name: String,
parent: Option<Box<KosmoraDirectory>>, parent: Option<Box<KosmoraDirectory>>,
children: Option<Vec<KosmoraINode>>, children: Option<Vec<KosmoraINode>>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct KosmoraINode { pub(crate) struct KosmoraINode {
inode: KosmoraINodeType, inode: KosmoraINodeType,
} }
impl KosmoraVfs { impl KosmoraVfsBuilder {
pub fn new() -> Self { pub fn new() -> Self {
KosmoraVfs { KosmoraVfsBuilder {
index: KosmoraIndex { index: Vec::new() }, index: KosmoraIndex { index: vec![] },
packages: Vec::new(), packages: vec![],
} }
} }
pub fn create_directory(virtual_path: &str) {} pub fn new_directory(&mut self, virtual_path: &str) -> Self {
pub fn add_directory(real_path: &str, virtual_path: &str) {} todo!()
pub fn add_file(real_path: &str, virtual_path: &str) {} }
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<KosmoraINode>; fn collect_directory_children(&self) -> Vec<KosmoraINode>;
fn to_kosmora_inode(&self) -> KosmoraINode; fn to_kosmora_inode(&self) -> KosmoraINode;
fn to_kosmora_directory(&self) -> KosmoraDirectory; fn to_kosmora_directory(&self) -> KosmoraDirectory;