include_dir/
dir_entry.rs
1use crate::{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 pub fn path(&self) -> &'a Path {
16 match self {
17 DirEntry::Dir(d) => d.path(),
18 DirEntry::File(f) => f.path(),
19 }
20 }
21
22 pub fn as_dir(&self) -> Option<&Dir<'a>> {
24 match self {
25 DirEntry::Dir(d) => Some(d),
26 DirEntry::File(_) => None,
27 }
28 }
29
30 pub fn as_file(&self) -> Option<&File<'a>> {
32 match self {
33 DirEntry::File(f) => Some(f),
34 DirEntry::Dir(_) => None,
35 }
36 }
37
38 pub fn children(&self) -> &'a [DirEntry<'a>] {
40 match self {
41 DirEntry::Dir(d) => d.entries(),
42 DirEntry::File(_) => &[],
43 }
44 }
45}