Skip to main content

dope_core/driver/route/
erased.rs

1use core::{marker, mem};
2
3use dope_sys::io::reactor::event::kind::Send;
4use o3::base::num::Epoch;
5
6use crate::driver::{
7    self,
8    retained::flight::Echo,
9    route::{Route, Selection, Token, indices::SlotIndex, kind},
10};
11
12/// Logical operation target with its native flight identity when submitted.
13#[derive(Clone, Copy)]
14#[repr(C)]
15pub struct Erased<'d, C, S: Selection = Route> {
16    pub(in crate::driver) token: Token,
17    pub(in crate::driver) flight: Option<Echo>,
18    pub(in crate::driver) driver: driver::Invariant<'d>,
19    pub(in crate::driver) class: marker::PhantomData<(C, S)>,
20}
21
22impl<'d> Erased<'d, kind::Any> {
23    pub(in crate::driver) const fn new(token: Token, driver: driver::Invariant<'d>) -> Self {
24        Self {
25            token,
26            flight: None,
27            driver,
28            class: marker::PhantomData,
29        }
30    }
31}
32
33impl<'d, C, S: Selection> Erased<'d, C, S> {
34    pub fn matches(self, target: Self) -> bool {
35        self.token == target.token
36    }
37
38    pub const fn route(self) -> Route {
39        match S::FIXED {
40            Some(route) => route,
41            None => self.token.route(),
42        }
43    }
44
45    pub const fn erase_route(self) -> Erased<'d, C> {
46        self.with_marker(Route::FRAMEWORK)
47    }
48
49    pub(crate) const fn with_marker<N: Selection>(self, _: N) -> Erased<'d, C, N> {
50        Erased {
51            token: self.token,
52            flight: self.flight,
53            driver: self.driver,
54            class: marker::PhantomData,
55        }
56    }
57
58    pub const fn slot(self) -> SlotIndex {
59        self.token.slot()
60    }
61
62    pub const fn epoch(self) -> Epoch {
63        self.token.epoch()
64    }
65
66    pub(crate) const fn into_token(self) -> Token {
67        self.token
68    }
69}
70
71impl<C, S: Selection> From<Erased<'_, C, S>> for Token {
72    fn from(target: Erased<'_, C, S>) -> Self {
73        target.token
74    }
75}
76
77const _: () = {
78    assert!(
79        mem::size_of::<Erased<'static, Send>>()
80            == mem::size_of::<Token>() + mem::size_of::<usize>()
81    );
82    assert!(mem::align_of::<Erased<'static, Send>>() == mem::align_of::<Token>());
83};