Skip to main content

datex_core/values/rust_values/duration/
mod.rs

1pub mod classification;
2mod convert_value;
3pub mod datex_hash;
4pub mod datex_native;
5
6use crate::{
7    prelude::*,
8    traits::{
9        convert_parts::{FromParts, HasPartsKind, IntoParts},
10        convert_value_container::ConvertValueContainer,
11        datex_native_only_structural::DatexNativeOnlyStructural,
12        datex_native_structural::DatexNativeStructural,
13        get_core_lib_type_id::GetCoreLibTypeId,
14        get_datex_type::GetDatexType,
15        value_access::ValueAccess,
16    },
17    value_updates::update_handler::{
18        UpdateCallbackDataAccess, UpdateHandlerImpl,
19    },
20    values::value_container::ValueContainer,
21};
22use core::time::Duration;
23
24mod to_instructions;
25#[cfg(feature = "ast")]
26mod to_datex_expression_data {
27    use crate::{
28        ast::expressions::DatexExpressionData,
29        traits::to_datex_expression_data::ToDatexExpressionData,
30        values::core_values::integer::Integer,
31    };
32    use core::time::Duration;
33
34    impl ToDatexExpressionData for Duration {
35        fn to_datex_expression_data(&self) -> DatexExpressionData {
36            // TODO: use amount once implemented
37            DatexExpressionData::Integer(Integer::from(self.as_millis()))
38        }
39    }
40}
41
42impl ValueAccess for Duration {}
43impl FromParts for Duration {
44    fn try_from_single_value_with_tag(
45        value: ValueContainer,
46        _tag: Option<&str>,
47    ) -> Result<Self, ()>
48    where
49        Self: Sized,
50    {
51        Self::try_from_value_container(value).map_err(|_| ())
52    }
53}
54impl IntoParts for Duration {
55    fn try_into_single_value<'a>(self: Box<Self>) -> Result<ValueContainer, ()>
56    where
57        Self: 'a + Sized,
58    {
59        Ok(self.to_value_container())
60    }
61}
62impl HasPartsKind for Duration {}
63impl GetCoreLibTypeId for Duration {}
64impl GetDatexType for Duration {}
65impl UpdateHandlerImpl for Duration {}
66impl UpdateCallbackDataAccess for Duration {}
67
68impl DatexNativeStructural for Duration {}
69impl DatexNativeOnlyStructural for Duration {}