use futures::io::{AsyncRead, AsyncWrite}; use pin_project::pin_project; use std::io::Error; use std::marker::Unpin; use std::ops::{Deref, DerefMut}; use std::pin::Pin; use std::task::{Context, Poll}; #[pin_project] #[derive(Debug)] pub(crate) struct Fuse { #[pin] pub t: T, pub u: U, } impl Fuse { pub(crate) fn new(t: T, u: U) -> Self { Self { t, u } } } impl Deref for Fuse { type Target = T; fn deref(&self) -> &T { &self.t } } impl DerefMut for Fuse { fn deref_mut(&mut self) -> &mut T { &mut self.t } } impl AsyncRead for Fuse { fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll> { self.project().t.poll_read(cx, buf) } } impl AsyncWrite for Fuse { fn poll_write( self: Pin<&mut Self>, cx: &mut Context, buf: &[u8], ) -> Poll> { self.project().t.poll_write(cx, buf) } fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { self.project().t.poll_flush(cx) } fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll> { self.project().t.poll_close(cx) } }