use crate::errors::Result;
use async_trait::async_trait;
use uuid::Uuid;
pub type VersionId = Uuid;
pub const NIL_VERSION_ID: VersionId = Uuid::nil();
pub type HistorySegment = Vec<u8>;
pub type Snapshot = Vec<u8>;
#[derive(Debug, PartialEq, Eq)]
pub enum AddVersionResult {
Ok(VersionId),
ExpectedParentVersion(VersionId),
}
#[derive(PartialEq, Debug, Clone, Copy, Eq, PartialOrd, Ord)]
pub enum SnapshotUrgency {
None,
Low,
High,
}
#[derive(Debug, PartialEq, Eq)]
pub enum GetVersionResult {
NoSuchVersion,
Version {
version_id: VersionId,
parent_version_id: VersionId,
history_segment: HistorySegment,
},
}
#[async_trait(?Send)]
pub trait Server {
async fn add_version(
&mut self,
parent_version_id: VersionId,
history_segment: HistorySegment,
) -> Result<(AddVersionResult, SnapshotUrgency)>;
async fn get_child_version(&mut self, parent_version_id: VersionId)
-> Result<GetVersionResult>;
async fn add_snapshot(&mut self, version_id: VersionId, snapshot: Snapshot) -> Result<()>;
async fn get_snapshot(&mut self) -> Result<Option<(VersionId, Snapshot)>>;
}