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    Q: executor::Startup,
17{
18    pub fn drive<R>(
19        &mut self,
20        now: clock::Deadline<'d>,
21        root: R,
22    ) -> Result<session::Fixed<'d, R::Output>, drive::Error>
23    where
24        R: root::Root<'d>,
25    {
26        use drive::clock::at;
27
28        self.access.core.check_time(now.into_raw())?;
29        self.access
30            .reborrow()
31            .drive_fixed(at(now), root, drive::tick)
32    }
33
34    pub fn drive_for<R>(
35        &mut self,
36        now: clock::Deadline<'d>,
37        timeout: time::Duration,
38        root: R,
39    ) -> Result<session::Fixed<'d, R::Output>, drive::Error>
40    where
41        R: root::Root<'d>,
42    {
43        use drive::clock::{Bound, at};
44
45        self.access.core.check_time(now.into_raw())?;
46        let source = Bound::until(at(now), timeout)?;
47        self.access
48            .reborrow()
49            .drive_fixed(source, root, drive::timeout)
50    }
51}
52
53impl<'app, 'life: 'app, 'd: 'life, D, Q> ops::Deref for Manual<'app, 'life, 'd, D, Q>
54where
55    D: executor::raw::Layout<'d>,
56{
57    type Target = session::access::Access<'app, 'life, 'd, D, Q>;
58
59    fn deref(&self) -> &Self::Target {
60        &self.access
61    }
62}
63
64impl<'d, D: executor::raw::Layout<'d>, Q> ops::DerefMut for Manual<'_, '_, 'd, D, Q> {
65    fn deref_mut(&mut self) -> &mut Self::Target {
66        &mut self.access
67    }
68}