pub(crate) mod diff;
pub mod map;
mod read;
mod repair;
pub use diff::DiffEntry;
pub use read::Snapshot;
#[cfg(test)]
mod test;
use crate::{
basic::persistent_btree::NodeId,
common::{RawBytes, ende::KeyEnDeOrdered, error::Result},
};
use serde::{Deserialize, Serialize};
use std::fmt;
macro_rules! define_id {
($(#[$doc:meta])* $name:ident) => {
$(#[$doc])*
#[derive(
Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
#[serde(transparent)]
pub struct $name(u64);
impl $name {
pub const fn from_raw(raw: u64) -> Self {
Self(raw)
}
pub const fn raw(self) -> u64 {
self.0
}
}
impl fmt::Display for $name {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(&self.0, f)
}
}
impl KeyEnDeOrdered for $name {
fn to_bytes(&self) -> RawBytes {
self.0.to_bytes()
}
fn from_slice(bytes: &[u8]) -> Result<Self> {
u64::from_slice(bytes).map(Self)
}
}
};
}
define_id! {
CommitId
}
define_id! {
BranchId
}
pub(crate) const NO_COMMIT: CommitId = CommitId(0);
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Commit {
pub(crate) id: CommitId,
pub(crate) root: NodeId,
pub(crate) parents: Vec<CommitId>,
pub(crate) timestamp_us: u64,
#[serde(default)]
pub(crate) ref_count: u32,
}
impl Commit {
pub fn id(&self) -> CommitId {
self.id
}
pub fn parents(&self) -> &[CommitId] {
&self.parents
}
pub fn timestamp_us(&self) -> u64 {
self.timestamp_us
}
}