Skip to main content

datex_core/datex_proxy/shared/
mod.rs

1pub mod datex_proxy;
2
3use crate::{
4    datex_proxy::{DatexValueContainerProxy, TryFromDatexValueError},
5    shared_values::SharedContainer,
6};
7
8pub struct Shared<T: DatexValueContainerProxy> {
9    value: T,
10    container: SharedContainer,
11}
12
13impl<T: DatexValueContainerProxy> Shared<T> {}
14
15impl<T: DatexValueContainerProxy> TryFrom<SharedContainer> for Shared<T> {
16    type Error = TryFromDatexValueError;
17    fn try_from(container: SharedContainer) -> Result<Self, Self::Error> {
18        let value =
19            T::try_from_value_container(container.value_container().clone())?;
20        Ok(Shared { value, container })
21    }
22}
23
24#[cfg(test)]
25mod test {
26    use super::*;
27    use crate::{
28        runtime::pointer_address_provider::SelfOwnedPointerAddressProvider,
29        shared_values::SharedContainerMutability,
30    };
31
32    use crate::prelude::*;
33    #[test]
34    fn string_shared() {
35        let address_provider = &mut SelfOwnedPointerAddressProvider::default();
36
37        let shared_container =
38            SharedContainer::new_owned_with_inferred_allowed_type(
39                "Hello DATEX",
40                SharedContainerMutability::Mutable,
41                address_provider,
42            );
43
44        let shared_string: Shared<String> =
45            Shared::try_from(shared_container).unwrap();
46        assert_eq!(shared_string.value, "Hello DATEX");
47    }
48}