use std::{
fmt::{self, Debug, Display, Formatter},
hash::Hash,
};
pub(crate) use self::{
delta::Footer as DFooter, entries::Entries, snapshot::Footer as SFooter, storage::Storage,
};
use uuid::Uuid;
mod delta;
mod entries;
mod error;
mod reader;
mod snapshot;
mod writer;
pub mod storage;
pub use self::{
error::{Error, Result},
reader::Reader,
writer::{LazyWriter, Writer},
};
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct LinkId(Uuid);
#[trait_variant::make(Send)]
pub trait Entry: Eq + Hash + Sized {
const SIZE: usize;
async fn read(reader: &mut storage::Reader) -> Result<Self>;
async fn write(&self, writer: &mut storage::Writer) -> Result<()>;
}
impl LinkId {
#[inline]
pub(crate) fn random() -> Self {
Self(Uuid::new_v4())
}
#[inline]
pub(crate) fn from_u128(num: u128) -> Self {
Self(Uuid::from_u128(num))
}
#[inline]
pub(crate) fn as_u128(&self) -> u128 {
self.0.as_u128()
}
}
impl Debug for LinkId {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "LinkId({})", self.0)
}
}
impl Display for LinkId {
#[inline]
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{}", self.0)
}
}