basyx_rs/
reference.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 serde::{Deserialize, Serialize};
7
8use crate::key::Key;
9use crate::ReferenceTypes;
10
11#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
12pub struct Reference {
13    #[serde(rename = "type")]
14    pub type_: ReferenceTypes,
15
16    /// E.g. semantic id of a standard submodel
17    #[serde(skip_serializing_if = "Option::is_none")]
18    #[serde(rename = "referredSemanticId")]
19    pub referred_semantic_id: Option<Box<Reference>>,
20
21    /// KeyType + Value, e.g. Submodel + https://example.com/ids/123456789
22    pub keys: Vec<Key>,
23}
24
25impl Reference {
26    pub fn new(type_: ReferenceTypes, key: Key) -> Self {
27        Self {
28            type_,
29            referred_semantic_id: None,
30            keys: vec![key],
31        }
32    }
33
34    pub fn new_from_vec(type_: ReferenceTypes, keys: Vec<Key>) -> Self {
35        Self {
36            type_,
37            referred_semantic_id: None,
38            keys,
39        }
40    }
41}