use std::fmt;
#[cfg(feature = "notify")]
pub mod filekind {
pub use notify::event::{
AccessKind, AccessMode, CreateKind, DataChange, EventKind as FileEventKind, MetadataKind,
ModifyKind, RemoveKind, RenameMode,
};
}
#[cfg(not(feature = "notify"))]
pub mod filekind {
pub use crate::sans_notify::{
AccessKind, AccessMode, CreateKind, DataChange, EventKind as FileEventKind, MetadataKind,
ModifyKind, RemoveKind, RenameMode,
};
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
pub enum FileType {
File,
Dir,
Symlink,
Other,
}
impl From<std::fs::FileType> for FileType {
fn from(ft: std::fs::FileType) -> Self {
if ft.is_file() {
Self::File
} else if ft.is_dir() {
Self::Dir
} else if ft.is_symlink() {
Self::Symlink
} else {
Self::Other
}
}
}
impl fmt::Display for FileType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::File => write!(f, "file"),
Self::Dir => write!(f, "dir"),
Self::Symlink => write!(f, "symlink"),
Self::Other => write!(f, "other"),
}
}
}