Skip to main content

dope_core/driver/retained/
mod.rs

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