Skip to main content

dope_core/driver/retained/
mod.rs

1//! Retained-owner driver access.
2
3use std::ops;
4
5use crate::driver;
6
7pub mod accept;
8pub mod arm;
9pub mod flight;
10pub mod raw;
11
12/// Driver access carrying retained-owner authority with the same representation
13/// as [`driver::Context`]. Submitting borrowed storage still requires the exact
14/// resource-retention proof documented at each raw submission boundary.
15#[repr(transparent)]
16pub struct Context<'a, 'owner, 'd: 'owner> {
17    pub(in crate::driver) driver: driver::Context<'a, 'd>,
18    owner: raw::Owner<'owner, 'd>,
19}
20
21impl<'a, 'owner, 'd: 'owner> Context<'a, 'owner, 'd> {
22    /// Joins driver access with a validated owner proof.
23    pub fn new(driver: driver::Context<'a, 'd>, owner: raw::Owner<'owner, 'd>) -> Self {
24        Self { driver, owner }
25    }
26
27    pub(crate) const fn token(&self) -> raw::Token<'owner, 'd> {
28        raw::Token::new(self.owner)
29    }
30
31    pub fn reborrow(&mut self) -> Context<'_, 'owner, 'd> {
32        Context {
33            driver: self.driver.reborrow(),
34            owner: self.owner,
35        }
36    }
37
38    pub fn driver(&mut self) -> &mut driver::Context<'a, 'd> {
39        &mut self.driver
40    }
41
42    /// Drops the owner proof while preserving the exact driver turn.
43    pub fn into_driver(self) -> driver::Context<'a, 'd> {
44        self.driver
45    }
46}
47
48impl<'a, 'owner, 'd: 'owner> ops::Deref for Context<'a, 'owner, 'd> {
49    type Target = driver::Context<'a, 'd>;
50
51    fn deref(&self) -> &Self::Target {
52        &self.driver
53    }
54}
55
56impl<'a, 'owner, 'd: 'owner> ops::DerefMut for Context<'a, 'owner, 'd> {
57    fn deref_mut(&mut self) -> &mut Self::Target {
58        &mut self.driver
59    }
60}
61
62const _: () = {
63    assert!(
64        std::mem::size_of::<Context<'static, 'static, 'static>>()
65            == std::mem::size_of::<driver::Context<'static, 'static>>()
66    );
67    assert!(
68        std::mem::align_of::<Context<'static, 'static, 'static>>()
69            == std::mem::align_of::<driver::Context<'static, 'static>>()
70    );
71};