use std::{
fs, io,
path::{Path, PathBuf},
};
#[derive(Debug)]
pub enum ItemType {
Directory,
File,
}
impl Default for ItemType {
fn default() -> Self {
Self::Directory
}
}
#[derive(Debug)]
pub struct FSItem {
pub path: PathBuf,
pub item_type: ItemType,
pub metadata: fs::Metadata,
}
impl TryFrom<&String> for FSItem {
type Error = io::Error;
fn try_from(s: &String) -> Result<Self, Self::Error> {
let path = Path::new(&s).canonicalize()?;
let metadata = fs::metadata(&path)?;
Ok(Self {
path,
item_type: if metadata.is_dir() {
ItemType::Directory
} else {
ItemType::File
},
metadata,
})
}
}