feat(proto): add generic proto writer
This commit is contained in:
parent
65f90ba600
commit
0a3683e2fa
4 changed files with 69 additions and 0 deletions
34
proto/src/writer/protowriter.rs
Normal file
34
proto/src/writer/protowriter.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use async_trait::async_trait;
|
||||
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) -> anyhow::Result<()>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl<W> ProtoFlush for ProtoWriter<W>
|
||||
where
|
||||
W: AsyncWrite + Unpin + Send,
|
||||
{
|
||||
async fn flush(&mut self) -> anyhow::Result<()> {
|
||||
self.inner.flush().await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue