use crate::{domain_event::DomainEvent, integration_event::IntegrationEvent};
use std::fmt::Debug;
pub trait IntegrationEventAdapter: Debug + Send + Sync + 'static {
type DomainEvent: DomainEvent;
type IntegrationEvent: IntegrationEvent;
fn to_integration_events(&self, domain_event: Self::DomainEvent) -> Vec<Self::IntegrationEvent>;
}
#[derive(Debug, Clone)]
pub struct NoOpIntegrationAdapter<D, I> {
_phantom: std::marker::PhantomData<(D, I)>,
}
impl<D, I> NoOpIntegrationAdapter<D, I> {
pub fn new() -> Self {
Self {
_phantom: std::marker::PhantomData,
}
}
}
impl<D, I> Default for NoOpIntegrationAdapter<D, I> {
fn default() -> Self {
Self::new()
}
}
impl<D, I> IntegrationEventAdapter for NoOpIntegrationAdapter<D, I>
where
D: DomainEvent,
I: IntegrationEvent,
{
type DomainEvent = D;
type IntegrationEvent = I;
fn to_integration_events(&self, _domain_event: Self::DomainEvent) -> Vec<Self::IntegrationEvent> {
vec![]
}
}