use std::{mem, path::PathBuf};
use crate::FsTree;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum TreeNode {
Regular,
Directory(Vec<FsTree>),
Symlink(PathBuf),
}
impl TreeNode {
pub fn is_same_type_as(&self, other: &Self) -> bool {
mem::discriminant(self) == mem::discriminant(other)
}
pub fn is_regular(&self) -> bool {
matches!(self, Self::Regular)
}
pub fn is_dir(&self) -> bool {
matches!(self, Self::Directory(_))
}
pub fn is_symlink(&self) -> bool {
matches!(self, Self::Symlink(_))
}
pub fn file_type_display(&self) -> &'static str {
match self {
Self::Regular => "regular file",
Self::Directory(_) => "directory",
Self::Symlink(_) => "symlink",
}
}
}
#[cfg(feature = "libc-file-type")]
impl TreeNode {
pub fn as_mode_t(&self) -> libc::mode_t {
match self {
TreeNode::Regular => libc::S_IFREG,
TreeNode::Directory(_) => libc::S_IFDIR,
TreeNode::Symlink(_) => libc::S_IFCHR,
}
}
}