Skip to main content

dope_fiber/abi/
ready.rs

1use core::task;
2
3use crate::{abi, context};
4
5#[repr(transparent)]
6#[must_use = "a fiber does nothing unless it is driven"]
7#[derive(Debug)]
8pub struct Ready<T> {
9    output: Option<T>,
10}
11
12impl<T> Unpin for Ready<T> {}
13
14impl<T> Ready<T> {
15    pub const fn new(output: T) -> Self {
16        Self {
17            output: Some(output),
18        }
19    }
20}
21
22impl<'d, T> abi::Fiber<'d> for Ready<T> {
23    type Output = T;
24
25    fn poll(call: context::PollCall<'_, '_, 'd, Self>) -> task::Poll<Self::Output> {
26        use core::task::Poll;
27        let this = call.into_fiber();
28        let Some(output) = this.get_mut().output.take() else {
29            return Poll::Pending;
30        };
31        Poll::Ready(output)
32    }
33}