Skip to main content

dope_sys/engine/admit/
mod.rs

1mod context;
2mod guard;
3pub mod raw;
4
5pub use context::Context;
6pub use guard::Guard;
7
8use std::fmt::Debug;
9
10use crate::io::{reactor::Full, request};
11
12pub type Cancellation<C> = Result<
13    Cancelled,
14    Error<
15        <<C as Context>::Native as Native>::Error<(
16            <C as Context>::Key,
17            Cause<<C as Context>::Failure>,
18        )>,
19    >,
20>;
21
22/// Reserves native capacity without consuming the host's operation ownership.
23pub trait Admit<C: Context>: Sized {
24    type Admission<'a>: Guard<C> + raw::Retain<C>
25    where
26        Self: 'a;
27
28    fn try_admit(&mut self) -> Result<Self::Admission<'_>, Full>;
29}
30
31pub trait Backend<C: Context>: Sized {
32    fn try_cancel<const FAMILY: u8>(
33        &mut self,
34        key: C::Key,
35        pending: bool,
36        slot: Option<&<C::Inputs as request::Context>::Target>,
37    ) -> Cancellation<C>;
38}
39
40#[derive(Clone, Copy, Debug, Eq, PartialEq)]
41pub enum Cancelled {
42    Submitted,
43    Queued,
44    Completed,
45}
46
47/// The native queue does not own the requested completion.
48#[derive(Clone, Copy, Debug, Eq, PartialEq)]
49pub struct Absent;
50
51/// Host-independent native admission and cancellation domains.
52pub trait Native {
53    type Selection: Copy + Eq + Debug;
54    type Permit;
55    type Error<F>;
56}
57
58/// Native preparation failed without changing the requested operation.
59#[derive(Clone, Copy, Debug, Eq, PartialEq)]
60pub enum Cause<F> {
61    Absent(Absent),
62    Reactor(F),
63}
64
65/// Queue exhaustion and rejected native state have distinct recovery paths.
66#[derive(Clone, Copy, Debug, Eq, PartialEq)]
67pub enum Error<E> {
68    Full(Full),
69    Rejected(E),
70}