use core::{future::Future, pin::Pin, task::Poll}; pub(crate) struct Reader { read: fn() -> Option, } impl Reader { pub fn new(read: fn() -> Option) -> Self { Self { read } } } impl Future for Reader { type Output = u8; fn poll(self: Pin<&mut Self>, cx: &mut core::task::Context<'_>) -> Poll { match (self.read)() { Some(c) => Poll::Ready(c), None => { cx.waker().wake_by_ref(); Poll::Pending } } } }