1use o3::mem::slot;
2use std::{ops, task, time};
3
4use crate::{
5 engine::{Buffer, Source, life, register},
6 io::reactor::ready::{delivery, store::Quota},
7};
8
9type Created<S, C, G> = (
10 <S as Source<C>>::Backend,
11 <<S as Source<C>>::Backend as Buffer>::Context,
12 <S as Create<C, G>>::Receive,
13);
14
15pub trait Register {
17 unsafe fn register(&mut self, source: register::Source<'_>) -> Result<(), register::Error>;
21}
22
23pub trait Resume<'a, R>
25where
26 R: life::Resume + 'a,
27 <R::Backend as Poll>::Context: 'a,
28{
29 unsafe fn try_resume(resolver: R) -> life::Retirement<R, R>;
33}
34
35pub trait Dispatch<'a, C, H, Q: delivery::Quota<H>>: Sized
37where
38 C: delivery::Context<H>,
39{
40 unsafe fn new(host: &'a mut H, quota: Q) -> Self;
43
44 fn dispatch(
45 self,
46 emit: impl for<'event> FnMut(
47 slot::Occupied<'event, C::Event>,
48 &mut H,
49 ) -> ops::ControlFlow<slot::Occupied<'event, C::Event>>,
50 ) -> C::Dispatch;
51}
52
53pub trait Poll {
55 type Context;
56 type Error: Copy + Eq;
57
58 unsafe fn commit<'a, Q: Quota>(
61 &'a mut self,
62 quota: Q,
63 deferred: impl FnOnce() -> bool,
64 ) -> Result<task::Poll<()>, Self::Error>
65 where
66 Self::Context: 'a;
67
68 unsafe fn wait<'a, Q: Quota>(
71 &'a mut self,
72 quota: Q,
73 timeout: Option<time::Duration>,
74 busy: bool,
75 ) -> Result<(), Self::Error>
76 where
77 Self::Context: 'a;
78}
79
80pub trait Create<C, G>: Source<C>
82where
83 Self::Backend: Buffer,
84{
85 type Receive;
86 type Error;
87
88 unsafe fn try_new(config: &G) -> Result<Created<Self, C, G>, Self::Error>;
92}