Skip to main content

datex_core/shared_values/
external_shared_container.rs

1use crate::shared_values::{
2    RemotePointerAddress, base_shared_value_container::BaseSharedValueContainer,
3};
4
5/// A shared container with an external pointer
6#[derive(Debug)]
7pub struct ExternalSharedContainer {
8    value: BaseSharedValueContainer,
9    /// Address of the remote pointer, can be a remote or builtin pointer address
10    address: RemotePointerAddress,
11}
12
13impl ExternalSharedContainer {
14    /// Create a new [ExternalSharedContainer] with a given [RemotePointerAddress].
15    /// # Safety
16    /// The caller must ensure that the [RemotePointerAddress] does not yet exist in the [SharedReferencesCache]
17    pub unsafe fn new(
18        shared_value_container: BaseSharedValueContainer,
19        address: RemotePointerAddress,
20    ) -> ExternalSharedContainer {
21        ExternalSharedContainer {
22            value: shared_value_container,
23            address,
24        }
25    }
26    pub fn value(&self) -> &BaseSharedValueContainer {
27        &self.value
28    }
29
30    pub fn value_mut(&mut self) -> &mut BaseSharedValueContainer {
31        &mut self.value
32    }
33
34    pub fn take_value(self) -> BaseSharedValueContainer {
35        self.value
36    }
37
38    pub fn address(&self) -> &RemotePointerAddress {
39        &self.address
40    }
41}