simple_shell/
reader.rs

1use core::{future::Future, pin::Pin, task::Poll};
2
3pub(crate) struct Reader {
4    read: fn() -> Option<u8>,
5}
6
7impl Reader {
8    pub fn new(read: fn() -> Option<u8>) -> Self {
9        Self { read }
10    }
11}
12
13impl Future for Reader {
14    type Output = u8;
15
16    fn poll(self: Pin<&mut Self>, cx: &mut core::task::Context<'_>) -> Poll<Self::Output> {
17        match (self.read)() {
18            Some(c) => Poll::Ready(c),
19            None => {
20                cx.waker().wake_by_ref();
21                Poll::Pending
22            }
23        }
24    }
25}