connection_utils/traits/
channel.rs

1use std::{fmt, pin::Pin};
2
3use async_trait::async_trait;
4use tokio::{io::{AsyncRead, AsyncWrite}, sync::watch};
5
6pub type TDataReader = Pin<Box<dyn AsyncRead + Send + 'static>>;
7pub type TDataWriter = Pin<Box<dyn AsyncWrite + Send + 'static>>;
8
9#[async_trait]
10pub trait Channel: AsyncRead + AsyncWrite + Send + Unpin + fmt::Debug + 'static {
11    fn id(&self) -> u16;
12    fn label(&self) -> &String;
13    fn is_closed(&self) -> bool;
14    
15    fn on_close(&self) -> watch::Receiver<bool>;
16
17    fn debug(
18        &self,
19        channel_type: &str,
20        f: &mut fmt::Formatter<'_>,
21    ) -> fmt::Result {
22        return f.debug_tuple(channel_type.as_ref())
23            .field(&self.id())
24            .field(&self.label())
25            .finish();
26    }
27
28    fn buffer_size(&self) -> u32;
29}