pub trait LocalEvtLog: Clone + 'static {
    type Id: Debug;
    type Error: StdError + Send + Sync + 'static;

    const MAX_SEQ_NO: NonZeroU64 = NonZeroU64::MAX;

    // Required methods
    async fn persist<E, ToBytes, ToBytesError>(
        &mut self,
        evt: &E,
        type_name: &str,
        id: &Self::Id,
        last_seq_no: Option<NonZeroU64>,
        to_bytes: &ToBytes
    ) -> Result<NonZeroU64, Self::Error>
       where E: Debug + Sync,
             ToBytes: Fn(&E) -> Result<Bytes, ToBytesError> + Sync,
             ToBytesError: StdError + Send + Sync + 'static;
    async fn last_seq_no(
        &self,
        type_name: &str,
        id: &Self::Id
    ) -> Result<Option<NonZeroU64>, Self::Error>;
    async fn evts_by_id<E, FromBytes, FromBytesError>(
        &self,
        type_name: &str,
        id: &Self::Id,
        after_seq_no: Option<NonZeroU64>,
        from_bytes: FromBytes
    ) -> Result<impl Stream<Item = Result<(NonZeroU64, E), Self::Error>> + Send, Self::Error>
       where E: Send,
             FromBytes: Fn(Bytes) -> Result<E, FromBytesError> + Copy + Send + Sync + 'static,
             FromBytesError: StdError + Send + Sync + 'static;
    async fn evts_by_type<E, FromBytes, FromBytesError>(
        &self,
        type_name: &str,
        after_seq_no: Option<NonZeroU64>,
        from_bytes: FromBytes
    ) -> Result<impl Stream<Item = Result<(NonZeroU64, E), Self::Error>> + Send, Self::Error>
       where E: Send,
             FromBytes: Fn(Bytes) -> Result<E, FromBytesError> + Copy + Send + Sync + 'static,
             FromBytesError: StdError + Send + Sync + 'static;
}
Expand description

Persistence for events.

Required Associated Types§

source

type Id: Debug

source

type Error: StdError + Send + Sync + 'static

Provided Associated Constants§

source

const MAX_SEQ_NO: NonZeroU64 = NonZeroU64::MAX

The maximum value for sequence numbers. Defaults to NonZeroU64::MAX unless overriden by an implementation.

Required Methods§

source

async fn persist<E, ToBytes, ToBytesError>( &mut self, evt: &E, type_name: &str, id: &Self::Id, last_seq_no: Option<NonZeroU64>, to_bytes: &ToBytes ) -> Result<NonZeroU64, Self::Error>
where E: Debug + Sync, ToBytes: Fn(&E) -> Result<Bytes, ToBytesError> + Sync, ToBytesError: StdError + Send + Sync + 'static,

Persist the given event and optional tag for the given entity type and ID and return the sequence number for the persisted event. The given last sequence number is used for optimistic locking, i.e. it must match the current last sequence number of the event log.

source

async fn last_seq_no( &self, type_name: &str, id: &Self::Id ) -> Result<Option<NonZeroU64>, Self::Error>

Get the last sequence number for the given entity type and ID.

source

async fn evts_by_id<E, FromBytes, FromBytesError>( &self, type_name: &str, id: &Self::Id, after_seq_no: Option<NonZeroU64>, from_bytes: FromBytes ) -> Result<impl Stream<Item = Result<(NonZeroU64, E), Self::Error>> + Send, Self::Error>
where E: Send, FromBytes: Fn(Bytes) -> Result<E, FromBytesError> + Copy + Send + Sync + 'static, FromBytesError: StdError + Send + Sync + 'static,

Get the events for the given entity ID starting after the given sequence number.

source

async fn evts_by_type<E, FromBytes, FromBytesError>( &self, type_name: &str, after_seq_no: Option<NonZeroU64>, from_bytes: FromBytes ) -> Result<impl Stream<Item = Result<(NonZeroU64, E), Self::Error>> + Send, Self::Error>
where E: Send, FromBytes: Fn(Bytes) -> Result<E, FromBytesError> + Copy + Send + Sync + 'static, FromBytesError: StdError + Send + Sync + 'static,

Get the events for the given entity type starting after the given sequence number.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> LocalEvtLog for T
where T: EvtLog,

§

type Id = <T as EvtLog>::Id

§

type Error = <T as EvtLog>::Error

source§

const MAX_SEQ_NO: NonZeroU64 = <Self as EvtLog>::MAX_SEQ_NO