use std::task::Poll; use tokio::io::{AsyncRead, AsyncWrite}; pub struct RepeatSome { bytes: &'static [u8], len: usize, } impl RepeatSome { pub fn new(bytes: &'static [u8]) -> Self { RepeatSome { bytes, len: bytes.len(), } } } impl AsyncRead for RepeatSome { fn poll_read( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, buf: &mut tokio::io::ReadBuf<'_>, ) -> std::task::Poll> { while buf.remaining() > self.len { buf.put_slice(self.bytes) } Poll::Ready(Ok(())) } } pub struct Drain {} impl Drain { pub fn new() -> Self { Drain {} } } impl AsyncWrite for Drain { fn poll_write( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, buf: &[u8], ) -> Poll> { Poll::Ready(Ok(buf.len())) } fn poll_flush( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> Poll> { Poll::Ready(Ok(())) } fn poll_shutdown( self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>, ) -> Poll> { Poll::Ready(Ok(())) } }