basyx_rs/
key.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 crate::key_types::KeyTypes;
7use serde::{Deserialize, Serialize};
8
9/// A key is a reference to an element by its ID.
10#[derive(Clone, PartialEq, Debug, Deserialize, Serialize)]
11pub struct Key {
12    /// Denotes which kind of entity is referenced
13    ///
14    // If Key/type = GlobalReference, the key represents a
15    // reference to a source that can be globally identified.
16
17    // If Key/type = FragmentReference, the key represents
18    // a bookmark or a similar local identifier within its parent
19    // element as specified by the key that precedes this key.
20
21    // In all other cases, the key references a model element
22    // of the same or another Asset Administration Shell. The
23    // name of the model element is explicitly listed.
24    #[serde(rename = "type")]
25    pub type_: KeyTypes,
26
27    /// The key value, for example an IRDI or an URI
28    pub value: String,
29}
30
31impl Key {
32    pub fn new(type_: KeyTypes, value: String) -> Self {
33        Self { type_, value }
34    }
35}