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::Proof<'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 {
25            driver,
26            owner: owner.into_proof(),
27        }
28    }
29
30    pub(crate) const fn token(&self) -> raw::Token<'owner, 'd> {
31        raw::Token::new(self.owner)
32    }
33
34    pub fn reborrow(&mut self) -> Context<'_, 'owner, 'd> {
35        Context {
36            driver: self.driver.reborrow(),
37            owner: self.owner,
38        }
39    }
40
41    pub fn driver(&mut self) -> &mut driver::Context<'a, 'd> {
42        &mut self.driver
43    }
44
45    /// Drops the owner proof while preserving the exact driver turn.
46    pub fn into_driver(self) -> driver::Context<'a, 'd> {
47        self.driver
48    }
49}
50
51impl<'a, 'owner, 'd: 'owner> ops::Deref for Context<'a, 'owner, 'd> {
52    type Target = driver::Context<'a, 'd>;
53
54    fn deref(&self) -> &Self::Target {
55        &self.driver
56    }
57}
58
59impl<'a, 'owner, 'd: 'owner> ops::DerefMut for Context<'a, 'owner, 'd> {
60    fn deref_mut(&mut self) -> &mut Self::Target {
61        &mut self.driver
62    }
63}
64
65const _: () = {
66    assert!(
67        std::mem::size_of::<Context<'static, 'static, 'static>>()
68            == std::mem::size_of::<driver::Context<'static, 'static>>()
69    );
70    assert!(
71        std::mem::align_of::<Context<'static, 'static, 'static>>()
72            == std::mem::align_of::<driver::Context<'static, 'static>>()
73    );
74};