1use crate::{wait::DriveWaitFor, ReadyOrNot};
2use core::{future::Future, marker::PhantomData};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub struct Empty {
7 pub(crate) _priv: (),
8}
9
10#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
12pub struct At<F: Future, Tail>
13{
14 pub(crate) node: ReadyOrNot<F>,
15 pub(crate) tail: Tail,
16 pub(crate) _holds_output: PhantomData<F::Output>,
18}
19
20pub trait FutList: DriveWaitFor {}
22
23impl FutList for Empty {}
24
25impl<F: Future + Unpin, T: FutList> FutList for At<F, T>
26{
27}
28
29pub struct Z(());
31
32pub struct S<I>(I);
34
35pub trait Detach<F: Future, I>
37{
38 type Output;
40
41 fn detach(self) -> (ReadyOrNot<F>, Self::Output);
43}
44
45impl<F: Future, T> Detach<F, Z> for At<F, T>
46{
47 type Output = T;
48
49 fn detach(self) -> (ReadyOrNot<F>, Self::Output) {
50 (self.node, self.tail)
51 }
52}
53
54impl<F: Future, I, H: Future, T> Detach<F, S<I>> for At<H, T>
55where
56 T: Detach<F, I>,
57{
58 type Output = At<H, T::Output>;
59
60 fn detach(self) -> (ReadyOrNot<F>, Self::Output) {
61 let (val, tail) = self.tail.detach();
62 (
63 val,
64 At {
65 node: self.node,
66 tail,
67 _holds_output: PhantomData,
68 },
69 )
70 }
71}