1use crate::probe::{Cause, Outcome, State, Stopped};
2
3type Fault<W, S> = Cause<
4 <W as Wait<S>>::Probe,
5 <<W as Wait<S>>::Outcome as Outcome>::Observation,
6 <W as Wait<S>>::Error,
7>;
8
9type Progress<W, S> = State<S, W>;
10type Transition<T, S, W> = Result<T, Stopped<S, Fault<W, S>>>;
11
12type Advanced<W, S> =
13 Result<(Progress<W, S>, <W as Wait<S>>::Outcome), Stopped<Progress<W, S>, Fault<W, S>>>;
14type Cancelled<W, S> = Result<S, Stopped<Progress<W, S>, Fault<W, S>>>;
15
16pub trait Wait<S>: Sized {
18 type Ring;
19 type Owned;
20 type Target;
21 type Probe: Copy;
22 type Outcome: Outcome<Probe = Self::Probe>;
23 type Error;
24
25 fn submit(
26 state: S,
27 ring: impl for<'a> FnOnce(&'a mut S) -> &'a mut Self::Ring,
28 entry: &Self::Owned,
29 probe: Self::Probe,
30 ) -> Result<Self, Stopped<S, Fault<Self, S>>>;
31
32 fn resume(
35 stopped: Stopped<Self, Fault<Self, S>>,
36 ring: impl for<'a> FnOnce(&'a mut S) -> &'a mut Self::Ring,
37 report: impl FnMut(Fault<Self, S>),
38 ) -> Result<Self, Stopped<Self, Fault<Self, S>>>;
39
40 fn finish(
41 self,
42 ring: impl for<'a> Fn(&'a mut S) -> &'a mut Self::Ring,
43 ) -> Transition<(S, Self::Outcome), S, Self>;
44
45 fn next(self, ring: impl for<'a> FnOnce(&'a mut S) -> &'a mut Self::Ring) -> Advanced<Self, S>;
46
47 fn cancel(self, ring: impl for<'a> Fn(&'a mut S) -> &'a mut Self::Ring) -> Cancelled<Self, S>;
48
49 unsafe fn option(
52 state: S,
53 access: impl for<'a> FnOnce(&'a mut S) -> (&'a mut Self::Ring, Self::Target, &'a libc::c_int),
54 probe: Self::Probe,
55 ) -> Result<Self, Stopped<S, Fault<Self, S>>>;
56
57 unsafe fn inspect<E>(
60 self,
61 check: impl FnOnce(&mut S) -> Result<(), E>,
62 ) -> Result<Self, Stopped<Self, E>>;
63}