Skip to main content

dope_sys/io/reactor/complete/
mod.rs

1use o3::{alloc, base::num::bounded, depot};
2
3use crate::Errno;
4
5pub mod flags;
6pub mod message;
7pub mod raw;
8pub mod resolve;
9
10type Header<E> = Parts<<E as Entry>::Token, <E as Entry>::Outcome, <E as Entry>::Flags>;
11
12/// Preserves the typed inputs of an emulated completion before rejection.
13pub trait Capture<E, S, F>: Sized {
14    fn operation(echo: E) -> Self;
15    fn creation(echo: E, queued: S, resolved: Option<S>) -> Self;
16    fn receive(echo: E, len: usize, flow: F) -> Self;
17}
18
19#[derive(Clone, Copy, Debug, Eq, PartialEq)]
20pub enum Decode<V, I> {
21    Value(V),
22    Error(Errno),
23    Invalid(I),
24}
25
26/// A completed owner routed to delivery or mandatory reclamation.
27pub enum Dequeued<E> {
28    Emit(E),
29    Reclaim(E),
30}
31
32/// A borrowed completion queue retaining its native publication order.
33pub trait Drain {
34    type Entry: Entry;
35
36    fn acquire(&mut self);
37    fn publish(&mut self);
38    fn refresh(&mut self);
39    fn len(&self) -> bounded::U32<0, { u32::MAX }>;
40    fn is_empty(&self) -> bool;
41    fn pop(&mut self) -> Option<Self::Entry>;
42}
43
44/// Inspects the next published completion without advancing either queue head.
45/// The returned borrow keeps the observed slot stable until an infallible commit.
46pub trait Inspect: Drain {
47    type Head<'a>: Head<Entry = Self::Entry>
48    where
49        Self: 'a;
50
51    fn front(&mut self) -> Option<Self::Head<'_>>;
52    fn available(&self) -> bounded::U32<0, { u32::MAX }>;
53}
54
55/// A published, unconsumed completion tied to the queue's exclusive borrow.
56pub trait Head: Sized {
57    type Entry: Entry;
58
59    fn parts(&self) -> Header<Self::Entry>
60    where
61        <Self::Entry as Entry>::Token: raw::Token;
62
63    /// Advances and publishes the head after every semantic check has succeeded.
64    fn commit(self);
65}
66
67pub trait Entry: Sized {
68    type Token;
69    type Outcome: Outcome;
70    type Flags: Flags;
71
72    fn into_parts(self) -> Parts<Self::Token, Self::Outcome, Self::Flags>
73    where
74        Self::Token: raw::Token;
75}
76
77pub trait Event {
78    type Key: Copy + Eq;
79
80    fn token(&self) -> Option<Self::Key>;
81    fn is_terminal(&self) -> bool;
82}
83
84/// Exact native completion evidence retained by a host decoder.
85pub trait Observe<T: Copy + Eq = (), S: Copy + Eq = (), F: Copy + Eq = ()> {
86    type Observation: Copy + Eq;
87}
88
89/// Separates successful values, native errors, and invalid kernel results.
90pub trait Outcome: Copy + Eq {
91    type Value: Copy + Eq + Into<bounded::U32<0, { i32::MAX as u32 }>>;
92    type Invalid: Copy + Eq;
93    type Returned: crate::kernel::Returned<Value = Self::Value, Invalid = Self::Invalid>;
94
95    fn decode(self) -> Decode<Self::Value, Self::Invalid>;
96    fn is_zero(self) -> bool;
97    /// Tests the native errno range without extracting its error payload.
98    fn is_error(self) -> bool;
99    fn canceled(self) -> Result<(), Self::Returned>;
100    fn bytes(self) -> Result<Result<Self::Value, crate::Errno>, Self::Returned>;
101    fn unit(self) -> Result<Result<(), crate::Errno>, Self::Returned>;
102    fn shutdown(self) -> Result<(), Self::Returned>;
103    fn stopped(self) -> Result<(), Self::Returned>;
104    fn aborted(self) -> Result<(), Self::Returned>;
105}
106
107/// Exact native completion fields retained before semantic interpretation.
108#[derive(Clone, Copy, Debug, Eq, PartialEq)]
109#[repr(C)]
110pub struct Parts<T, O, F> {
111    pub token: T,
112    pub outcome: O,
113    pub flags: F,
114}
115
116pub trait Queue: Sized {
117    type Event: Event;
118    type Capacity: depot::raw::Count;
119    type Vacancy<'a>: Vacancy<Event = Self::Event>
120    where
121        Self: 'a;
122
123    fn try_new(capacity: Self::Capacity) -> Result<Self, alloc::Error>;
124
125    fn vacant(&mut self) -> Option<Self::Vacancy<'_>>;
126
127    fn pop_front(&mut self) -> Option<Dequeued<Self::Event>>;
128
129    fn suppress(&mut self, key: <Self::Event as Event>::Key);
130
131    fn is_terminal(&self, key: <Self::Event as Event>::Key) -> bool;
132
133    fn is_empty(&self) -> bool;
134
135    fn available(&self) -> usize;
136}
137
138/// Preserves the exact native completion fields before semantic rejection.
139pub trait Record<T>: Sized {
140    type Outcome;
141    type Flags;
142
143    fn new(token: T, outcome: Self::Outcome, flags: Self::Flags) -> Self;
144}
145
146impl<T, O, F> Record<T> for Parts<T, O, F> {
147    type Outcome = O;
148    type Flags = F;
149
150    fn new(token: T, outcome: O, flags: F) -> Self {
151        Self {
152            token,
153            outcome,
154            flags,
155        }
156    }
157}
158
159pub trait Source {
160    type Queue<E: Event, C: depot::raw::Count>: Queue<Event = E, Capacity = C>;
161}
162
163pub trait Vacancy: Sized {
164    type Event: Event;
165
166    fn push(self, event: Self::Event);
167}
168
169/// Retains both decoded metadata and the exact rejected native flags.
170pub trait Flags: Copy + Eq + From<Self::Meta> {
171    type Meta: flags::Meta;
172    type Invalid: Copy + Eq + Into<Self>;
173
174    fn meta(self) -> Self::Meta;
175    fn decode(self) -> Result<Self::Meta, Self::Invalid>;
176    fn is_valid(self) -> bool;
177}