1use std::{ops, os::fd, task, time};
2
3use crate::{
4 engine::{Buffer, Source, life, register},
5 io::reactor::ready::{delivery, store::Quota},
6};
7
8type Created<S, C, G> = (
9 <S as Source<C>>::Backend,
10 <<S as Source<C>>::Backend as Buffer>::Context,
11 <S as Create<C, G>>::Receive,
12);
13
14pub trait Register {
16 unsafe fn register(&mut self, source: fd::BorrowedFd<'_>) -> Result<(), register::Error>;
20}
21
22pub trait Resume<'a, R>
24where
25 R: life::Resume + 'a,
26 <R::Backend as Poll>::Context: 'a,
27{
28 unsafe fn try_resume(resolver: R) -> life::Retirement<R, R>;
32}
33
34pub trait Dispatch<'a, C, H, Q: delivery::Quota<H>>: Sized
36where
37 C: delivery::Context<H>,
38{
39 unsafe fn new(host: &'a mut H, quota: Q) -> Self;
42
43 fn dispatch(
44 self,
45 emit: impl FnMut(C::Event, &mut H) -> ops::ControlFlow<C::Event>,
46 ) -> C::Dispatch;
47}
48
49pub trait Poll {
51 type Context;
52 type Error: Copy + Eq;
53
54 unsafe fn commit<'a, Q: Quota>(
57 &'a mut self,
58 quota: Q,
59 deferred: impl FnOnce() -> bool,
60 ) -> Result<task::Poll<()>, Self::Error>
61 where
62 Self::Context: 'a;
63
64 unsafe fn wait<'a, Q: Quota>(
67 &'a mut self,
68 quota: Q,
69 timeout: Option<time::Duration>,
70 busy: impl FnOnce() -> bool,
71 ) -> Result<(), Self::Error>
72 where
73 Self::Context: 'a;
74}
75
76pub trait Create<C, G>: Source<C>
78where
79 Self::Backend: Buffer,
80{
81 type Receive;
82 type Error;
83
84 unsafe fn try_new(config: &G) -> Result<Created<Self, C, G>, Self::Error>;
88}