1#[doc(hidden)]
2pub mod __private;
3
4mod batch;
5mod future;
6mod pending;
7mod pollfn;
8mod ready;
9mod scoped;
10mod waitfn;
11
12use core::pin::Pin;
13use core::task::Poll;
14
15use super::{Context, Waiter};
16pub use batch::{Batch, BatchOutput};
17pub use future::lazy::Lazy;
18pub use pending::Pending;
19pub use pollfn::PollFn;
20pub use ready::Ready;
21pub use waitfn::WaitFn;
22
23pub const fn pending<T>() -> Pending<T> {
24 Pending::new()
25}
26
27pub const fn poll_fn<'d, F, T>(f: F) -> PollFn<'d, F, T>
28where
29 F: FnMut(Pin<&mut Context<'_, 'd>>) -> Poll<T>,
30{
31 PollFn::new(f)
32}
33
34pub const fn ready<T>(output: T) -> Ready<T> {
35 Ready::new(output)
36}
37
38pub const fn wait_fn<'d, F, T>(f: F) -> WaitFn<'d, F, T>
39where
40 F: FnMut(Pin<&mut Context<'_, 'd>>, Pin<&Waiter<'d>>) -> Poll<T>,
41{
42 WaitFn::new(f)
43}
44
45pub trait Fiber<'d> {
46 type Output;
47
48 fn poll(self: Pin<&mut Self>, cx: Pin<&mut Context<'_, 'd>>) -> Poll<Self::Output>;
49}
50
51pub trait IntoFiber<'d> {
52 type Output;
53 type IntoFiber: Fiber<'d, Output = Self::Output>;
54
55 fn into_fiber(self) -> Self::IntoFiber;
56}
57
58impl<'d, F> IntoFiber<'d> for F
59where
60 F: Fiber<'d>,
61{
62 type Output = F::Output;
63 type IntoFiber = Self;
64
65 fn into_fiber(self) -> Self::IntoFiber {
66 self
67 }
68}