use std::{ io::Write, path::PathBuf, process::{Command, Stdio}, time::{Duration, SystemTime}, }; pub use self::error::Error; pub use self::git::GitProject; pub use self::path::PathProject; mod error; mod git; mod path; pub type ProjectItem = Box>; pub trait Project: Timestamp { fn to_path_buf(&self) -> &PathBuf; } impl Project for T where T: Timestamp, T: AsRef, { fn to_path_buf(&self) -> &PathBuf { self.as_ref() } } pub trait Timestamp { type Error; fn timestamp(&self) -> Result; } impl Timestamp for T where T: AsRef, { type Error = Error; fn timestamp(&self) -> Result { self.as_ref() .metadata()? .modified()? .duration_since(SystemTime::UNIX_EPOCH) .map_err(Into::into) } } pub trait Preview { type Error; fn preview(&self) -> Result<(), Self::Error>; } impl Preview for T where T: AsRef, { type Error = std::io::Error; fn preview(&self) -> Result<(), Self::Error> { let output = Command::new("ls") .arg("-l") .arg("-a") .arg(self.to_path_buf()) .stdout(Stdio::piped()) .output()?; std::io::stdout().write_all(&output.stdout) } }