use std::{error::Error, fmt::Debug, hash::Hash, sync::Arc};
use async_trait::async_trait;
use crate::Path;
pub trait Key
where
Self: Clone + Debug + Eq + Hash,
{
fn new() -> Self;
fn as_filename(&self) -> String;
}
#[cfg(feature = "uuid-as-key")]
impl Key for uuid::Uuid {
fn new() -> Self {
uuid::Uuid::new_v4()
}
fn as_filename(&self) -> String {
self.to_string()
}
}
#[async_trait]
pub trait AsyncFileRepr
where
Self: Sized,
{
type Err: Error;
async fn load(path: impl AsRef<Path> + Send) -> Result<Self, Self::Err>;
async fn flush(self: &Arc<Self>, path: impl AsRef<Path> + Send) -> Result<(), Self::Err>;
async fn delete(path: impl AsRef<Path> + Send) -> Result<(), Self::Err>;
}