connection-utils 0.8.0

Connection related utilities.
Documentation
use std::{fmt, pin::Pin};

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();
    }

    fn buffer_size(&self) -> u32;
}