Skip to main content

dope_runtime/executor/raw/
activate.rs

1use std::{mem, pin};
2
3use dope_core::driver::{
4    self,
5    route::{self, kind},
6    schedule,
7};
8
9use crate::executor;
10
11/// Route activation authority for one exact retained root and scheduler turn.
12#[must_use]
13pub struct Activate<'driver, 'turn, 'd> {
14    drive: executor::raw::Drive<'driver, 'turn, 'd>,
15    target: route::Erased<'d, kind::Any>,
16}
17
18impl<'driver, 'turn, 'd> Activate<'driver, 'turn, 'd> {
19    pub(crate) const fn new(
20        target: route::Erased<'d, kind::Any>,
21        turn: schedule::Turn<'turn, 'd>,
22        driver: driver::Context<'driver, 'd>,
23    ) -> Self {
24        Self {
25            drive: executor::raw::Drive { turn, driver },
26            target,
27        }
28    }
29
30    pub const fn target(&self) -> route::Erased<'d, kind::Any> {
31        self.target
32    }
33
34    pub fn reborrow(&mut self) -> Activate<'_, '_, 'd> {
35        Activate {
36            drive: self.drive.reborrow(),
37            target: self.target,
38        }
39    }
40
41    pub(crate) fn wake<R>(self, app: pin::Pin<&mut R>)
42    where
43        R: executor::raw::App<'d>,
44    {
45        if !R::WAKE_ROUTES.has_route(self.target.route()) {
46            return;
47        }
48        // SAFETY: the session view admits only a target declared by the
49        // activation route set and supplies its exact installed pinned root.
50        unsafe { R::activate(app, self) };
51    }
52
53    pub fn into_driver(self) -> (route::Erased<'d, kind::Any>, driver::Context<'driver, 'd>) {
54        (self.target, self.drive.driver)
55    }
56
57    pub fn into_parts(
58        self,
59    ) -> (
60        route::Erased<'d, kind::Any>,
61        schedule::Turn<'turn, 'd>,
62        driver::Context<'driver, 'd>,
63    ) {
64        let executor::raw::Drive { turn, driver } = self.drive;
65        (self.target, turn, driver)
66    }
67}
68
69const _: () = {
70    assert!(
71        mem::size_of::<Activate<'static, 'static, 'static>>()
72            == mem::size_of::<executor::raw::Drive<'static, 'static, 'static>>()
73                + mem::size_of::<route::Erased<'static, kind::Any>>()
74    );
75    assert!(mem::align_of::<Activate<'static, 'static, 'static>>() == mem::align_of::<usize>());
76};