summaryrefslogtreecommitdiffstats
path: root/src/project.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/project.rs')
-rw-r--r--src/project.rs47
1 files changed, 41 insertions, 6 deletions
diff --git a/src/project.rs b/src/project.rs
index 1188c88..b13d4a7 100644
--- a/src/project.rs
+++ b/src/project.rs
@@ -1,12 +1,47 @@
-use std::{path::PathBuf, time::Duration};
+use std::{
+ path::PathBuf,
+ time::{Duration, SystemTime},
+};
-pub use git::GitProject;
-pub use path::PathProject;
+pub use self::error::Error;
+pub use self::git::GitProject;
+pub use self::path::PathProject;
+mod error;
mod git;
mod path;
-pub trait Project {
- fn timestamp(&self) -> Option<Duration>;
- fn to_path_buf(&self) -> PathBuf;
+pub trait Timestamp {
+ type Error;
+
+ fn timestamp(&self) -> Result<Duration, Self::Error>;
+}
+
+impl<T> Timestamp for T
+where
+ T: AsRef<PathBuf>,
+{
+ type Error = Error;
+
+ fn timestamp(&self) -> Result<Duration, Self::Error> {
+ self.as_ref()
+ .metadata()?
+ .modified()?
+ .duration_since(SystemTime::UNIX_EPOCH)
+ .map_err(Into::into)
+ }
+}
+
+pub trait Project: Timestamp {
+ fn to_path_buf(&self) -> &PathBuf;
+}
+
+impl<T> Project for T
+where
+ T: Timestamp,
+ T: AsRef<PathBuf>,
+{
+ fn to_path_buf(&self) -> &PathBuf {
+ self.as_ref()
+ }
}