fix(tonic): Remove Sync requirement for streams (#804)

This commit is contained in:
Lucio Franco
2021-10-24 21:48:05 -04:00
committed by GitHub
parent 1f3df8db9e
commit 23c1392fb7
31 changed files with 207 additions and 165 deletions
+51
View File
@@ -2,3 +2,54 @@ pub mod pb {
tonic::include_proto!("test");
tonic::include_proto!("stream");
}
pub mod mock {
use std::{
pin::Pin,
task::{Context, Poll},
};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tonic::transport::server::Connected;
#[derive(Debug)]
pub struct MockStream(pub tokio::io::DuplexStream);
impl Connected for MockStream {
type ConnectInfo = ();
/// Create type holding information about the connection.
fn connect_info(&self) -> Self::ConnectInfo {}
}
impl AsyncRead for MockStream {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_read(cx, buf)
}
}
impl AsyncWrite for MockStream {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
Pin::new(&mut self.0).poll_write(cx, buf)
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_flush(cx)
}
fn poll_shutdown(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}
}
}