use std::{fmt::Display}; use async_trait::async_trait; use errors::{DeserializeError, PersistenceError, SerializeError}; #[async_trait] pub trait Persistence { async fn insert(&self, event_info: &EventInfo, content: Vec) -> anyhow::Result<()>; async fn next(&self) -> Option; 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, Copy)] pub struct EventInfo { pub domain: &'static str, pub entity_type: &'static str, pub event_name: &'static str, } 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::*;