@@ -11,3 +11,4 @@ tokio.workspace = true
|
||||
thiserror.workspace = true
|
||||
async-trait.workspace = true
|
||||
uuid.workspace = true
|
||||
futures.workspace = true
|
||||
|
@@ -27,6 +27,18 @@ pub enum PublishError {
|
||||
ConnectionError(#[source] anyhow::Error),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SubscriptionError {
|
||||
#[error("failed to subscribe: {0}")]
|
||||
FailedToSubscribe(#[source] anyhow::Error),
|
||||
|
||||
#[error("connection failed: {0}")]
|
||||
ConnectionFailed(#[source] TransportError),
|
||||
|
||||
#[error("failed to deserialize{0}")]
|
||||
DeserializationFailed(#[source] DeserializeError),
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum TransportError {
|
||||
#[error("to publish to transport {0}")]
|
||||
|
@@ -38,7 +38,11 @@ impl Display for EventInfo {
|
||||
}
|
||||
|
||||
pub trait Event: Serializer + Deserializer {
|
||||
fn event_info(&self) -> EventInfo;
|
||||
fn event_info() -> EventInfo;
|
||||
|
||||
fn int_event_info(&self) -> EventInfo {
|
||||
Self::event_info()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod errors;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
use std::{pin::Pin, sync::Arc};
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -6,7 +6,19 @@ use crate::{errors::TransportError, EventInfo};
|
||||
|
||||
#[async_trait]
|
||||
pub trait Transport {
|
||||
type Stream: futures::Stream<Item = Vec<u8>>;
|
||||
|
||||
async fn publish(&self, event_info: &EventInfo, content: Vec<u8>)
|
||||
-> Result<(), TransportError>;
|
||||
async fn subscriber(
|
||||
&self,
|
||||
event_info: &EventInfo,
|
||||
) -> Result<Option<Self::Stream>, TransportError>;
|
||||
}
|
||||
pub type DynTransport = Arc<dyn Transport + Send + Sync + 'static>;
|
||||
|
||||
pub type DynTransport = Arc<
|
||||
dyn Transport<Stream = Pin<Box<dyn futures::Stream<Item = Vec<u8>> + Send>>>
|
||||
+ Send
|
||||
+ Sync
|
||||
+ 'static,
|
||||
>;
|
||||
|
Reference in New Issue
Block a user