1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[derive(Debug, Clone)]
pub struct File<Metadata> {
    pub contents: Vec<u8>,
    pub mode: u32,
    pub metadata: Option<Metadata>,
}

impl<Metadata> File<Metadata> {
    pub fn new(contents: Vec<u8>) -> Self {
        Self {
            contents,
            mode: 0o644,
            metadata: None,
        }
    }
}

#[derive(Debug, Clone, Default)]
pub struct Dir {
    pub mode: u32,
}

impl Dir {
    pub fn new() -> Self {
        Self { mode: 0o644 }
    }
}

#[derive(Debug, Clone)]
pub enum Node<Metadata> {
    File(File<Metadata>),
    Dir(Dir),
}

impl<Metadata> Node<Metadata> {
    pub fn is_file(&self) -> bool {
        match *self {
            Node::File(_) => true,
            _ => false,
        }
    }

    pub fn is_dir(&self) -> bool {
        match *self {
            Node::Dir(_) => true,
            _ => false,
        }
    }
}