use std::fs;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum FileType
{
File,
Dir,
Symlink,
}
#[allow(missing_docs)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Metadata
{
pub file_type: FileType,
pub len: u64,
}
impl FileType
{
#[must_use]
pub fn is_dir(&self) -> bool
{
*self == Self::Dir
}
#[must_use]
pub fn is_file(&self) -> bool
{
*self == Self::File
}
#[must_use]
pub fn is_symlink(&self) -> bool
{
*self == Self::Symlink
}
}
impl Metadata
{
#[must_use]
pub const fn file_type(&self) -> FileType
{
self.file_type
}
#[must_use]
pub fn is_dir(&self) -> bool
{
self.file_type == FileType::Dir
}
#[must_use]
pub fn is_file(&self) -> bool
{
self.file_type == FileType::File
}
#[must_use]
pub fn is_symlink(&self) -> bool
{
self.file_type == FileType::Symlink
}
#[must_use]
pub const fn len(&self) -> u64
{
self.len
}
#[must_use]
pub const fn is_empty(&self) -> bool
{
self.len == 0
}
}
impl From<fs::Metadata> for Metadata
{
fn from(metadata: fs::Metadata) -> Self
{
Self {
file_type: if metadata.is_dir()
{
FileType::Dir
}
else if metadata.is_file()
{
FileType::File
}
else
{
FileType::Symlink
},
len: metadata.len(),
}
}
}