use std::fs;
use std::path::Path;
use std::time;
pub trait PathExt {
fn metadata_modified(&self) -> Option<time::SystemTime>;
fn newer_than<P>(&self, other: P) -> bool
where
P: AsRef<Self>;
}
impl PathExt for Path {
fn metadata_modified(&self) -> Option<time::SystemTime> {
fs::metadata(self).and_then(|m| m.modified()).ok()
}
fn newer_than<P>(&self, other: P) -> bool
where
P: AsRef<Self>,
{
match (self.metadata_modified(), other.as_ref().metadata_modified()) {
(Some(self_time), Some(other_time)) => self_time > other_time,
_ => false,
}
}
}