use std::fmt::Display; use async_trait::async_trait; use errors::{DeserializeError, PersistenceError, SerializeError}; pub trait Tx: Send + Sync {} pub type DynTx = Box; #[async_trait] pub trait Persistence { async fn insert(&self, event_info: &EventInfo, content: Vec) -> anyhow::Result<()>; async fn next(&self) -> Result, PersistenceError>; async fn get(&self, event_id: &str) -> Result)>, PersistenceError>; async fn update_published(&self, event_id: &str) -> Result<(), PersistenceError>; } pub trait Serializer { fn serialize(&self) -> Result, SerializeError>; } pub trait Deserializer { fn deserialize(raw: Vec) -> Result where Self: Sized; } #[derive(Debug, Clone)] pub struct EventInfo { pub domain: String, pub entity_type: String, pub event_name: String, } impl Display for EventInfo { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.write_str(&format!( "domain: {}, entity_type: {}", self.domain, self.entity_type )) } } pub trait Event: Serializer + Deserializer { fn event_info() -> EventInfo; fn int_event_info(&self) -> EventInfo { Self::event_info() } } pub mod errors; mod transport; pub use transport::*;