use async_trait::async_trait; use tokio::io; use tokio::io::{AsyncWrite, AsyncWriteExt}; pub struct ProtoWriter where W: AsyncWrite + Unpin + Send, { pub(super) inner: W, } impl ProtoWriter where W: AsyncWrite + Unpin + Send, { pub fn new(writer: W) -> ProtoWriter { ProtoWriter { inner: writer } } } #[async_trait] pub trait ProtoFlush { async fn flush(&mut self) -> Result<(), io::Error>; } #[async_trait] impl ProtoFlush for ProtoWriter where W: AsyncWrite + Unpin + Send, { async fn flush(&mut self) -> Result<(), io::Error> { self.inner.flush().await?; Ok(()) } }