use async_trait::async_trait;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum ReaderFilter {
All,
Tag(String),
PersistenceId(String),
PersistenceIds(Vec<String>),
}
#[async_trait]
pub trait Reader: Send + 'static {
type Event: Send + Clone + 'static;
type Projection: Default + Send + Sync + 'static;
type Error: std::error::Error + Send + 'static;
fn name(&self) -> &str;
fn tag(&self) -> Option<String> {
None
}
fn filter(&self) -> ReaderFilter {
match self.tag() {
Some(t) => ReaderFilter::Tag(t),
None => ReaderFilter::All,
}
}
fn decode(bytes: &[u8]) -> Result<Self::Event, String>;
async fn apply(
&mut self,
projection: &mut Self::Projection,
event: Self::Event,
) -> Result<(), Self::Error>;
}