New architecture
This commit is contained in:
parent
e4b3424ba6
commit
907a4962c5
61 changed files with 2742 additions and 3100 deletions
|
|
@ -1,32 +1,33 @@
|
|||
use std::error::Error;
|
||||
use std::fs::read_dir;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub trait Storage {
|
||||
fn write_filename(&self) -> String;
|
||||
fn read_filename(&self) -> Result<String, Box<dyn Error>>;
|
||||
fn write_filename(&self) -> PathBuf;
|
||||
fn read_filename(&self) -> Result<PathBuf, Box<dyn Error>>;
|
||||
fn recent_date(&self) -> Result<u64, Box<dyn Error>>;
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SimpleStorage(String, String);
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SimpleStorage(PathBuf);
|
||||
|
||||
impl SimpleStorage {
|
||||
pub const fn new(base: String, filename: String) -> Self {
|
||||
Self(base, filename)
|
||||
pub const fn new(base: PathBuf) -> Self {
|
||||
Self(base)
|
||||
}
|
||||
|
||||
fn get_path(&self, date: Option<u64>) -> String {
|
||||
fn get_path(&self, date: Option<u64>) -> PathBuf {
|
||||
match date {
|
||||
Some(d) => format!("{}/_{}/{}", self.0, self.1, d),
|
||||
None => format!("{}/_{}", self.0, self.1),
|
||||
Some(d) => self.0.join(d.to_string()),
|
||||
None => self.0.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Storage for SimpleStorage {
|
||||
fn write_filename(&self) -> String {
|
||||
fn write_filename(&self) -> PathBuf {
|
||||
self.get_path(Some(
|
||||
SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
|
@ -35,7 +36,7 @@ impl Storage for SimpleStorage {
|
|||
))
|
||||
}
|
||||
|
||||
fn read_filename(&self) -> Result<String, Box<dyn Error>> {
|
||||
fn read_filename(&self) -> Result<PathBuf, Box<dyn Error>> {
|
||||
Ok(self.get_path(Some(self.recent_date()?)))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue