basyx_rs/submodel_element/
property.rs

1// SPDX-FileCopyrightText: 2021 Fraunhofer Institute for Experimental Software Engineering IESE
2// SPDX-FileCopyrightText: 2023 Jan Hecht
3//
4// SPDX-License-Identifier: MIT
5
6use super::EmbeddedDataSpecification;
7use crate::LangString as LangStringNameType;
8use crate::LangString as LangStringTextType;
9use crate::{qualifier::Qualifier, reference::Reference, DataTypeDefXsd, Extension};
10use serde::{Deserialize, Serialize};
11
12// #[cfg(feature = "explorer")]
13// use super::ValueType;
14
15#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
16pub struct Property {
17    // Referable
18    // HasExtension
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub extensions: Option<Vec<Extension>>,
21
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub category: Option<String>,
24
25    #[serde(skip_serializing_if = "Option::is_none")]
26    #[serde(rename = "idShort")]
27    pub id_short: Option<String>,
28
29    #[serde(skip_serializing_if = "Option::is_none")]
30    #[serde(rename = "displayName")]
31    pub display_name: Option<Vec<LangStringNameType>>,
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub description: Option<Vec<LangStringTextType>>,
35
36    // HasSemantics
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[serde(rename = "semanticId")]
39    pub semantic_id: Option<Reference>,
40
41    #[serde(skip_serializing_if = "Option::is_none")]
42    #[serde(rename = "supplementalSemanticIds")]
43    pub supplemental_semantic_ids: Option<Vec<Reference>>,
44
45    // Qualifiable
46    #[serde(skip_serializing_if = "Option::is_none")]
47    pub qualifiers: Option<Vec<Qualifier>>,
48
49    // HasDataSpecification
50    #[serde(skip_serializing_if = "Option::is_none")]
51    #[serde(rename = "embeddedDataSpecifications")]
52    pub embedded_data_specifications: Option<Vec<EmbeddedDataSpecification>>,
53
54    // Property
55    //#[cfg(feature = "explorer")]
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub value: Option<String>,
58    // #[cfg(not(feature = "explorer"))]
59    // #[serde(skip_serializing_if = "Option::is_none")]
60    // pub value: Option<Value>,
61    #[serde(skip_serializing_if = "Option::is_none")]
62    #[serde(rename = "valueId")]
63    pub value_id: Option<Reference>,
64
65    // #[cfg(feature = "explorer")]
66    #[serde(rename = "valueType")]
67    pub value_type: DataTypeDefXsd,
68    // #[cfg(not(feature = "explorer"))] // TODO clarify this feature
69    // pub value_type: String,
70}
71
72impl Property {
73    pub fn new(value_type: DataTypeDefXsd) -> Self {
74        Self {
75            // #[cfg(feature = "explorer")]
76            // value: {
77            //     if let Some(v) = value {
78            //         v.to_string()
79            //     } else {
80            //         String::from("")
81            //     }
82            // },
83            // #[cfg(not(feature = "explorer"))]
84            // value,
85            extensions: None,
86            category: None,
87            id_short: None,
88            display_name: None,
89            description: None,
90            semantic_id: None,
91            supplemental_semantic_ids: None,
92            qualifiers: None,
93            embedded_data_specifications: None,
94            value: None,
95            value_id: None,
96            //#[cfg(feature = "explorer")]
97            value_type,
98            // #[cfg(not(feature = "explorer"))]
99            // value_type: value_type.to_string();
100        }
101    }
102}