From da884530e2b3e0b9a5bef9abcf683a970b93bd6b Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Mon, 28 Nov 2022 16:09:29 -0600 Subject: feat: add git and preview (default) features --- src/project.rs | 55 +++++++++++++++---------------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) (limited to 'src/project.rs') diff --git a/src/project.rs b/src/project.rs index e6faf66..5486dc1 100644 --- a/src/project.rs +++ b/src/project.rs @@ -1,19 +1,15 @@ -use std::{ - io::Write, - path::PathBuf, - process::{Command, Stdio}, - time::{Duration, SystemTime}, -}; +use std::{path::PathBuf, time::Duration}; pub use self::error::Error; -pub use self::git::GitProject; -pub use self::path::PathProject; mod error; -mod git; -mod path; +pub mod path; -pub type ProjectItem = Box>; +#[cfg(feature = "git")] +pub mod git; + + +pub type ProjectItem = Box; pub trait Project: Timestamp { fn to_path_buf(&self) -> &PathBuf; @@ -29,47 +25,26 @@ where } } -pub trait Timestamp { - type Error; +pub trait ProjectParser { + fn parse_project(&self, path_buf: PathBuf) -> Option; +} - fn timestamp(&self) -> Result; +pub trait Timestamp { + fn timestamp(&self) -> &Duration; } impl Timestamp for T where - T: AsRef, + T: AsRef, { - type Error = Error; - - fn timestamp(&self) -> Result { + fn timestamp(&self) -> &Duration { self.as_ref() - .metadata()? - .modified()? - .duration_since(SystemTime::UNIX_EPOCH) - .map_err(Into::into) } } +#[cfg(feature = "preview")] 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) - } -} -- cgit v1.2.3-70-g09d2