use crate::{Dir, File};
use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DirEntry {
Dir(Dir),
File(File),
}
impl DirEntry {
pub fn path(&self) -> &'static Path {
match self {
DirEntry::Dir(d) => d.path(),
DirEntry::File(f) => f.path(),
}
}
pub fn as_dir(&self) -> Option<&Dir> {
match self {
DirEntry::Dir(d) => Some(d),
DirEntry::File(_) => None,
}
}
pub fn as_file(&self) -> Option<&File> {
match self {
DirEntry::File(f) => Some(f),
DirEntry::Dir(_) => None,
}
}
pub fn children(&self) -> &'static [DirEntry] {
match self {
DirEntry::Dir(d) => d.entries(),
DirEntry::File(_) => &[],
}
}
pub fn is_file(&self) -> bool {
matches!(self, Self::File(_))
}
pub fn is_dir(&self) -> bool {
matches!(self, Self::Dir(_))
}
}