2023-09-23 22:38:12 +02:00
|
|
|
use std::{pin::Pin, sync::Arc};
|
2023-09-23 18:21:39 +02:00
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
|
|
|
use crate::{errors::TransportError, EventInfo};
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait Transport {
|
2023-09-23 22:38:12 +02:00
|
|
|
type Stream: futures::Stream<Item = Vec<u8>>;
|
|
|
|
|
2023-09-23 18:21:39 +02:00
|
|
|
async fn publish(&self, event_info: &EventInfo, content: Vec<u8>)
|
|
|
|
-> Result<(), TransportError>;
|
2023-09-23 22:38:12 +02:00
|
|
|
async fn subscriber(
|
|
|
|
&self,
|
|
|
|
event_info: &EventInfo,
|
|
|
|
) -> Result<Option<Self::Stream>, TransportError>;
|
2023-09-23 18:21:39 +02:00
|
|
|
}
|
2023-09-23 22:38:12 +02:00
|
|
|
|
|
|
|
pub type DynTransport = Arc<
|
|
|
|
dyn Transport<Stream = Pin<Box<dyn futures::Stream<Item = Vec<u8>> + Send>>>
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>;
|