use std::{ops, os::fd, task, time};
use crate::{
engine::{Buffer, Source, life, register},
io::reactor::ready::{delivery, store::Quota},
};
type Created<S, C, G> = (
<S as Source<C>>::Backend,
<<S as Source<C>>::Backend as Buffer>::Context,
<S as Create<C, G>>::Receive,
);
pub trait Register {
unsafe fn register(&mut self, source: fd::BorrowedFd<'_>) -> Result<(), register::Error>;
}
pub trait Resume<'a, R>
where
R: life::Resume + 'a,
<R::Backend as Poll>::Context: 'a,
{
unsafe fn try_resume(resolver: R) -> life::Retirement<R, R>;
}
pub trait Dispatch<'a, C, H, Q: delivery::Quota<H>>: Sized
where
C: delivery::Context<H>,
{
unsafe fn new(host: &'a mut H, quota: Q) -> Self;
fn dispatch(
self,
emit: impl FnMut(C::Event, &mut H) -> ops::ControlFlow<C::Event>,
) -> C::Dispatch;
}
pub trait Poll {
type Context;
type Error: Copy + Eq;
unsafe fn commit<'a, Q: Quota>(
&'a mut self,
quota: Q,
deferred: impl FnOnce() -> bool,
) -> Result<task::Poll<()>, Self::Error>
where
Self::Context: 'a;
unsafe fn wait<'a, Q: Quota>(
&'a mut self,
quota: Q,
timeout: Option<time::Duration>,
busy: impl FnOnce() -> bool,
) -> Result<(), Self::Error>
where
Self::Context: 'a;
}
pub trait Create<C, G>: Source<C>
where
Self::Backend: Buffer,
{
type Receive;
type Error;
unsafe fn try_new(config: &G) -> Result<Created<Self, C, G>, Self::Error>;
}