tfserver/structures/
temp_transport.rs1use std::io;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
5
6pub struct TempTransport<'a, T: AsyncRead + AsyncWrite + Unpin + Send + Sync> {
8 base_transport: &'a mut T,
9}
10
11impl<'a, T: AsyncRead + AsyncWrite + Unpin + Send + Sync> TempTransport<'a, T> {
12 pub fn new(transport: &'a mut T) -> Self {
13 TempTransport {
14 base_transport: transport,
15 }
16 }
17}
18
19impl<'a, T: AsyncRead + AsyncWrite + Unpin + Send + Sync> AsyncRead for TempTransport<'a, T> {
20 fn poll_read(
21 mut self: Pin<&mut Self>,
22 cx: &mut Context<'_>,
23 buf: &mut ReadBuf<'_>,
24 ) -> Poll<io::Result<()>> {
25 Pin::new(&mut *self.base_transport).poll_read(cx, buf)
26 }
27}
28
29impl<'a, T: AsyncRead + AsyncWrite + Unpin + Send + Sync> AsyncWrite for TempTransport<'a, T> {
30 fn poll_write(
31 mut self: Pin<&mut Self>,
32 cx: &mut Context<'_>,
33 buf: &[u8],
34 ) -> Poll<io::Result<usize>> {
35 Pin::new(&mut *self.base_transport).poll_write(cx, buf)
36 }
37
38 fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
39 Pin::new(&mut *self.base_transport).poll_flush(cx)
40 }
41
42 fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
43 Pin::new(&mut *self.base_transport).poll_shutdown(cx)
44 }
45}