use async_trait::async_trait;
use std::error::Error;
use std::fmt::Debug;
#[async_trait]
pub trait StateBackend {
type State: Clone + State + 'static;
type Err: Debug + Error + 'static;
async fn write(&self, upd: SnapshotedUpdate<Self::State>) -> Result<(), Self::Err>;
async fn updates(&self) -> Result<Vec<SnapshotedUpdate<Self::State>>, Self::Err>;
}
pub trait State {
type Update: Clone + PartialEq + Send + 'static;
type Err: Debug + Error + 'static;
const TABLE: &'static str = "updates";
fn update(&mut self, upd: Self::Update) -> Result<(), Self::Err>;
}
#[derive(Debug, Clone, PartialEq)]
pub enum SnapshotedUpdate<St: State> {
Incremental(St::Update),
Snapshot(St),
}
impl<St: State> SnapshotedUpdate<St> {
pub fn is_snapshot(&self) -> bool {
matches!(self, SnapshotedUpdate::Snapshot(_))
}
}