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