use crate::SeqNo;
use bytes::Bytes;
use futures::Stream;
use std::{error::Error as StdError, fmt::Debug, future::Future, num::NonZeroU64};
use uuid::Uuid;
pub trait EvtLog: Clone + Send + Sync + 'static {
type Error: StdError + Send + Sync;
const MAX_SEQ_NO: SeqNo = SeqNo::new(NonZeroU64::MAX);
fn persist<'a, E, EvtToBytes, EvtToBytesError>(
&'a mut self,
id: Uuid,
evt: &'a E,
tag: Option<String>,
evt_to_bytes: &'a EvtToBytes,
) -> impl Future<Output = Result<SeqNo, Self::Error>> + Send
where
E: Debug + Send + Sync + 'a,
EvtToBytes: Fn(&E) -> Result<Bytes, EvtToBytesError> + Send + Sync,
EvtToBytesError: StdError + Send + Sync + 'static;
fn last_seq_no(
&self,
id: Uuid,
) -> impl Future<Output = Result<Option<SeqNo>, Self::Error>> + Send + '_;
fn evts_by_id<'a, E, EvtFromBytes, EvtFromBytesError>(
&'a self,
id: Uuid,
from_seq_no: SeqNo,
evt_from_bytes: EvtFromBytes,
) -> impl Future<
Output = Result<impl Stream<Item = Result<(SeqNo, E), Self::Error>> + Send, Self::Error>,
> + Send
where
E: Debug + Send + 'a,
EvtFromBytes: Fn(Bytes) -> Result<E, EvtFromBytesError> + Copy + Send + Sync + 'static,
EvtFromBytesError: StdError + Send + Sync + 'static;
fn evts_by_tag<'a, E, T, EvtFromBytes, EvtFromBytesError>(
&'a self,
tag: T,
from_seq_no: SeqNo,
evt_from_bytes: EvtFromBytes,
) -> impl Future<
Output = Result<impl Stream<Item = Result<(SeqNo, E), Self::Error>> + Send, Self::Error>,
> + Send
where
E: Debug + Send + 'a,
EvtFromBytes: Fn(Bytes) -> Result<E, EvtFromBytesError> + Copy + Send + Sync + 'static,
EvtFromBytesError: StdError + Send + Sync + 'static,
T: Into<String> + Send;
}