use serde::{de::DeserializeOwned, Serialize};
use thiserror::Error;
#[derive(Debug, Error)]
pub enum CrdtError {
#[error("Serialization error: {0}")]
Serialization(String),
#[error("Deserialization error: {0}")]
Deserialization(String),
#[error("Merge error: {0}")]
Merge(String),
#[error("Validation error: {0}")]
Validation(String),
#[error("Invalid input: {0}")]
InvalidInput(String),
#[error("Internal error: {0}")]
Internal(String),
}
pub trait CrdtReader<'a> {
fn is_empty(&self) -> Result<bool, CrdtError>;
}
pub trait Crdt: Clone + Serialize + DeserializeOwned + Send + Sync {
type Reader<'a>: CrdtReader<'a>
where
Self: 'a;
fn merge_from_readers(readers: &[Self::Reader<'_>]) -> Result<Self, CrdtError>
where
Self: Sized;
fn validate(&self) -> Result<(), CrdtError>;
fn is_empty(&self) -> bool;
fn to_capnp_bytes(&self) -> Vec<u8>;
}