connection_utils/traits/
connection.rs

1use anyhow::Result;
2use async_trait::async_trait;
3use tokio::sync::broadcast::Receiver;
4
5use super::Channel;
6
7pub type TOnRemoteChannelReader = Receiver<Box<dyn Channel>>;
8
9#[async_trait]
10pub trait Disconnected: Send {
11    async fn connect(mut self: Box<Self>) -> Result<Box<dyn Connected>>;
12    async fn accept_connection(mut self: Box<Self>) -> Result<Box<dyn Connected>>;
13}
14
15#[async_trait]
16pub trait Connected: Send {
17    fn on_remote_channel(&mut self) -> Result<TOnRemoteChannelReader>;
18    fn off_remote_channel(&mut self, data: TOnRemoteChannelReader) -> Result<()>;
19
20    async fn channel(&mut self, label: String, buffer_size: usize) -> Result<Box<dyn Channel>>;
21    // async fn shutdown(mut self) -> Result<()>;
22}