use crate::error::ApplyError;
use crate::message::EventMetadatas;
use event_store::prelude::RecordedEvent;
use futures::future::BoxFuture;
use std::any::TypeId;
use std::collections::BTreeMap;
pub(crate) mod handler;
#[doc(hidden)]
pub mod resolver;
pub use handler::EventHandler;
#[doc(hidden)]
pub use handler::EventHandlerInstance;
pub trait Event: Send {
fn into_envelope<'de>(event: RecordedEvent) -> Result<crate::message::EventEnvelope<Self>, ()>
where
Self: serde::Deserialize<'de> + serde::de::Deserialize<'de>,
Self: 'static + Clone,
{
let r = Self::deserialize(event.data).map_err(|_| ())?;
Ok(crate::message::EventEnvelope {
event: r,
meta: EventMetadatas {
correlation_id: event.correlation_id,
causation_id: event.causation_id,
stream_name: event.stream_uuid,
},
})
}
}
pub trait EventApplier<E: Event> {
fn apply(&mut self, event: &E) -> Result<(), ApplyError>;
}
pub trait Handler<E: crate::event::Event> {
fn handle(&mut self, event: &E) -> BoxFuture<Result<(), ()>>;
}