xtask_todo_lib/devshell/vfs/
node.rs1#[derive(Debug, Clone, PartialEq)]
4pub enum Node {
5 Dir { name: String, children: Vec<Self> },
6 File { name: String, content: Vec<u8> },
7}
8
9impl Node {
10 #[must_use]
11 pub fn name(&self) -> &str {
12 match self {
13 Self::Dir { name, .. } | Self::File { name, .. } => name,
14 }
15 }
16 #[must_use]
17 pub const fn is_dir(&self) -> bool {
18 matches!(self, Self::Dir { .. })
19 }
20 #[must_use]
21 pub const fn is_file(&self) -> bool {
22 matches!(self, Self::File { .. })
23 }
24
25 #[must_use]
27 pub fn child(&self, name: &str) -> Option<&Self> {
28 match self {
29 Self::Dir { children, .. } => children.iter().find(|c| c.name() == name),
30 Self::File { .. } => None,
31 }
32 }
33}