rama_utils/include_dir/
dir_entry.rs1use super::{Dir, File};
2use std::path::Path;
3
4#[derive(Debug, Clone, PartialEq)]
6pub enum DirEntry<'a> {
7 Dir(Dir<'a>),
9 File(File<'a>),
11}
12
13impl<'a> DirEntry<'a> {
14 #[must_use]
16 pub fn path(&self) -> &'a Path {
17 match self {
18 DirEntry::Dir(d) => d.path(),
19 DirEntry::File(f) => f.path(),
20 }
21 }
22
23 #[must_use]
25 pub fn as_dir(&self) -> Option<&Dir<'a>> {
26 match self {
27 DirEntry::Dir(d) => Some(d),
28 DirEntry::File(_) => None,
29 }
30 }
31
32 #[must_use]
34 pub fn as_file(&self) -> Option<&File<'a>> {
35 match self {
36 DirEntry::File(f) => Some(f),
37 DirEntry::Dir(_) => None,
38 }
39 }
40
41 #[must_use]
43 pub fn children(&self) -> &'a [Self] {
44 match self {
45 DirEntry::Dir(d) => d.entries(),
46 DirEntry::File(_) => &[],
47 }
48 }
49}