Skip to main content

dope_runtime/executor/session/
manual.rs

1use std::{ops, time};
2
3use dope_core::driver::schedule::clock;
4
5use crate::executor::{self, drive, root, session};
6
7/// Installed application scope whose protocol time is caller-controlled.
8#[repr(transparent)]
9pub struct Manual<'app, 'life: 'app, 'd: 'life, D: executor::raw::Layout<'d>, Q = ()> {
10    pub(super) access: session::access::Access<'app, 'life, 'd, D, Q>,
11}
12
13impl<'app, 'life: 'app, 'd: 'life, D, Q> Manual<'app, 'life, 'd, D, Q>
14where
15    D: executor::raw::App<'d>,
16{
17    pub fn drive<R>(
18        &mut self,
19        now: clock::Deadline<'d>,
20        root: R,
21    ) -> Result<session::Fixed<'d, R::Output>, drive::Error>
22    where
23        R: root::Root<'d>,
24    {
25        use drive::clock::at;
26
27        self.access.core.check_time(now.into_raw())?;
28        self.access
29            .reborrow()
30            .drive_fixed(at(now), root, drive::tick)
31    }
32
33    pub fn drive_for<R>(
34        &mut self,
35        now: clock::Deadline<'d>,
36        timeout: time::Duration,
37        root: R,
38    ) -> Result<session::Fixed<'d, R::Output>, drive::Error>
39    where
40        R: root::Root<'d>,
41    {
42        use drive::clock::{Bound, at};
43
44        self.access.core.check_time(now.into_raw())?;
45        let source = Bound::until(at(now), timeout)?;
46        self.access
47            .reborrow()
48            .drive_fixed(source, root, drive::timeout)
49    }
50}
51
52impl<'app, 'life: 'app, 'd: 'life, D, Q> ops::Deref for Manual<'app, 'life, 'd, D, Q>
53where
54    D: executor::raw::Layout<'d>,
55{
56    type Target = session::access::Access<'app, 'life, 'd, D, Q>;
57
58    fn deref(&self) -> &Self::Target {
59        &self.access
60    }
61}
62
63impl<'d, D: executor::raw::Layout<'d>, Q> ops::DerefMut for Manual<'_, '_, 'd, D, Q> {
64    fn deref_mut(&mut self) -> &mut Self::Target {
65        &mut self.access
66    }
67}