1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::pin::Pin;
use std::fmt;

use async_trait::async_trait;
use tokio::{io::{AsyncRead, AsyncWrite}, sync::watch};

pub type TDataReader = Pin<Box<dyn AsyncRead + Send + 'static>>;
pub type TDataWriter = Pin<Box<dyn AsyncWrite + Send + 'static>>;

#[async_trait]
pub trait Channel: AsyncRead + AsyncWrite + Send + Unpin + fmt::Debug + 'static {
    fn id(&self) -> u16;
    fn label(&self) -> &String;
    fn is_closed(&self) -> bool;
    
    fn on_close(&self) -> watch::Receiver<bool>;

    fn debug(
        &self,
        channel_type: &str,
        f: &mut fmt::Formatter<'_>,
    ) -> fmt::Result {
        return f.debug_tuple(channel_type.as_ref())
            .field(&self.id())
            .field(&self.label())
            .finish();
    }
}