Hey,
Im trying to wrap an Tokio Stream (tokio::net::TcpStream) with an enum. I found this on (stackoverflow with a similar problem. I was able to modify it to compile.
If I change that code example to use an Enum instead of a struct I keep running into problems and cant seem to figure out how to get it work. Any help or insight would be great! Thanks!
use std::io::Result;
use core::pin::Pin;
use core::task::{Context, Poll};
use tokio::io::ReadBuf;
use tokio::io::AsyncRead;
use std::io;
pub struct Wrapper<T: AsyncRead + std::marker::Unpin>{
inner: T
}
impl<T: AsyncRead + std::marker::Unpin> AsyncRead for Wrapper<T> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
Pin::new(&mut self.inner).poll_read(cx, buf)
}
}
pub enum WrapperEnum<T: AsyncRead + std::marker::Unpin>{
Foo{inner: T},
Bar{inner: T}
}
impl<T: AsyncRead + std::marker::Unpin> AsyncRead for WrapperEnum<T> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
match &*self {
WrapperEnum::Foo{inner} => Pin::new(&mut inner).poll_read(cx, buf),
WrapperEnum::Foo{inner} => Pin::new(&mut inner).poll_read(cx, buf)
}
}
}