use std::path::PathBuf;
use std::time::SystemTime;
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DirEntryKind {
File,
Directory,
Symlink,
}
#[derive(Debug, Clone)]
pub struct DirEntry {
pub name: String,
pub kind: DirEntryKind,
pub size: u64,
pub modified: Option<SystemTime>,
pub permissions: Option<u32>,
pub symlink_target: Option<PathBuf>,
}
impl DirEntry {
pub fn directory(name: impl Into<String>) -> Self {
Self {
name: name.into(),
kind: DirEntryKind::Directory,
size: 0,
modified: None,
permissions: None,
symlink_target: None,
}
}
pub fn file(name: impl Into<String>, size: u64) -> Self {
Self {
name: name.into(),
kind: DirEntryKind::File,
size,
modified: None,
permissions: None,
symlink_target: None,
}
}
pub fn symlink(name: impl Into<String>, target: impl Into<PathBuf>) -> Self {
Self {
name: name.into(),
kind: DirEntryKind::Symlink,
size: 0,
modified: None,
permissions: None,
symlink_target: Some(target.into()),
}
}
pub fn is_dir(&self) -> bool {
self.kind == DirEntryKind::Directory
}
pub fn is_file(&self) -> bool {
self.kind == DirEntryKind::File
}
pub fn is_symlink(&self) -> bool {
self.kind == DirEntryKind::Symlink
}
}