Cargo format

This commit is contained in:
Adrian Heine 2019-09-12 22:59:32 +02:00
parent 9bab810b91
commit 8c0224e983
44 changed files with 1784 additions and 611 deletions

View file

@ -20,14 +20,19 @@ impl SimpleStorage {
fn get_path(&self, date: Option<u64>) -> String {
match date {
Some(d) => format!("{}/_{}/{}", self.0, self.1, d),
None => format!("{}/_{}", self.0, self.1)
None => format!("{}/_{}", self.0, self.1),
}
}
}
impl Storage for SimpleStorage {
fn write_filename(&self) -> String {
self.get_path(Some(SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs()))
self.get_path(Some(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
))
}
fn read_filename(&self) -> Result<String, Box<dyn Error>> {
@ -37,8 +42,15 @@ impl Storage for SimpleStorage {
fn recent_date(&self) -> Result<u64, Box<dyn Error>> {
let dir = self.get_path(None);
try!(read_dir(dir))
.map(|entry| entry.ok().and_then(|e| e.file_name().into_string().ok()).and_then(|filename| u64::from_str(&filename).ok()))
.fold(None, |maybe_newest, maybe_time| maybe_newest.into_iter().chain(maybe_time).max())
.ok_or_else(|| "Not found".to_string().into())
.map(|entry| {
entry
.ok()
.and_then(|e| e.file_name().into_string().ok())
.and_then(|filename| u64::from_str(&filename).ok())
})
.fold(None, |maybe_newest, maybe_time| {
maybe_newest.into_iter().chain(maybe_time).max()
})
.ok_or_else(|| "Not found".to_string().into())
}
}