Skip to main content

dope_core/driver/route/kind/
mod.rs

1use core::mem;
2
3use dope_sys::io::reactor::event::kind::{
4    self, Accept, Connect, Native, Open, Read, Recv, Send, SendOwned, Shape, Socket, Sync, Tuning,
5    Write,
6};
7
8mod sealed;
9pub(super) use sealed::Sealed;
10
11/// Compile-time proof of one operation class accepted by the driver.
12pub trait Class: Sealed + Copy {
13    /// Operation class this marker selects.
14    const KIND: Kind;
15
16    /// Protocol code of this class, derived from its single class tag.
17    const CODE: Code = Code::new(Self::KIND as u8);
18}
19
20/// An operation class which can own one native flight.
21///
22/// An unclassified target cannot enter the flight arena:
23///
24/// Framework controls do not own native flights:
25pub trait Flight: Class + kind::Flight {}
26
27impl<C: Class + kind::Flight> Flight for C {}
28
29/// Opaque operation-class code used only by the route encoder.
30#[derive(Clone, Copy, Eq, PartialEq)]
31#[repr(transparent)]
32pub struct Code(u8);
33
34impl Code {
35    pub(crate) const fn new(raw: u8) -> Self {
36        Self(raw)
37    }
38
39    pub(crate) const fn raw(self) -> u8 {
40        self.0
41    }
42
43    pub(crate) const fn native(kind: Native) -> Self {
44        match kind {
45            Native::SendOwned => Self::new(Kind::Send as u8),
46            kind => Self::new(kind as u8),
47        }
48    }
49}
50
51const _: () = assert!(mem::size_of::<Code>() == mem::size_of::<u8>());
52
53#[derive(Clone, Copy, Eq, PartialEq, Debug)]
54#[repr(u8)]
55pub enum Kind {
56    Unspecified = 0,
57    Accept = 1,
58    Recv = 2,
59    Send = 3,
60    Socket = 5,
61    Connect = 6,
62    Shutdown = 7,
63    Open = 11,
64    OneShot = 19,
65    TaskQueue = 21,
66    Tuning = 25,
67    Write = 28,
68    Sync = 29,
69    Read = 30,
70}
71
72#[derive(Clone, Copy, Debug, Eq, PartialEq)]
73#[repr(transparent)]
74pub struct Unknown(u8);
75
76#[derive(Clone, Copy, Debug)]
77pub enum Any {}
78#[derive(Clone, Copy)]
79pub enum Shutdown {}
80#[derive(Clone, Copy)]
81pub enum OneShot {}
82#[derive(Clone, Copy)]
83pub enum TaskQueue {}
84impl Sealed for Any {}
85impl Sealed for Shutdown {}
86impl Sealed for OneShot {}
87impl Sealed for TaskQueue {}
88impl Class for Any {
89    const KIND: Kind = Kind::Unspecified;
90}
91
92impl Class for Accept {
93    const KIND: Kind = Kind::Accept;
94}
95
96impl Class for Recv {
97    const KIND: Kind = Kind::Recv;
98}
99
100impl Class for Send {
101    const KIND: Kind = Kind::Send;
102}
103
104impl Class for SendOwned {
105    const KIND: Kind = Kind::Send;
106}
107
108impl Class for Socket {
109    const KIND: Kind = Kind::Socket;
110}
111
112impl Class for Connect {
113    const KIND: Kind = Kind::Connect;
114}
115
116impl Class for Shutdown {
117    const KIND: Kind = Kind::Shutdown;
118}
119
120impl Class for Open {
121    const KIND: Kind = Kind::Open;
122}
123
124impl Class for OneShot {
125    const KIND: Kind = Kind::OneShot;
126}
127
128impl Class for TaskQueue {
129    const KIND: Kind = Kind::TaskQueue;
130}
131
132impl Class for Tuning {
133    const KIND: Kind = Kind::Tuning;
134}
135
136impl Class for Write {
137    const KIND: Kind = Kind::Write;
138}
139
140impl Class for Sync {
141    const KIND: Kind = Kind::Sync;
142}
143
144impl Class for Read {
145    const KIND: Kind = Kind::Read;
146}
147
148impl Unknown {
149    pub(crate) const fn new(raw: u8) -> Self {
150        Self(raw)
151    }
152}
153
154const _: () = {
155    assert!(mem::size_of::<Shape>() == 1);
156    assert!(mem::size_of::<Native>() == mem::size_of::<Kind>());
157};