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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::file::File;
use std::path::Path;
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Dir<'a> {
#[doc(hidden)]
pub path: &'a str,
#[doc(hidden)]
pub files: &'a [File<'a>],
#[doc(hidden)]
pub dirs: &'a [Dir<'a>],
}
impl<'a> Dir<'a> {
pub fn path(&self) -> &'a Path {
Path::new(self.path)
}
pub fn files(&self) -> &'a [File<'a>] {
self.files
}
pub fn dirs(&self) -> &'a [Dir<'a>] {
self.dirs
}
pub fn contains<S: AsRef<Path>>(&self, path: S) -> bool {
let path = path.as_ref();
self.get_file(path).is_some() || self.get_dir(path).is_some()
}
pub fn get_dir<S: AsRef<Path>>(&self, path: S) -> Option<Dir<'a>> {
let path = path.as_ref();
for dir in self.dirs {
if Path::new(dir.path) == path {
return Some(*dir);
}
if let Some(d) = dir.get_dir(path) {
return Some(d);
}
}
None
}
pub fn get_file<S: AsRef<Path>>(&self, path: S) -> Option<File<'a>> {
let path = path.as_ref();
for file in self.files {
if Path::new(file.path) == path {
return Some(*file);
}
}
for dir in self.dirs {
if let Some(d) = dir.get_file(path) {
return Some(d);
}
}
None
}
}