cooplan_definitions_lib/
attribute.rs1use serde::{Deserialize, Serialize};
2
3use super::source_attribute::SourceAttribute;
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
7pub struct Attribute {
8 pub id: String,
9 pub name: String,
10 pub data_type: String,
11 pub unit: Option<String>,
12 pub optional: bool,
13}
14
15impl Attribute {
16 pub fn to_source_attribute(&self) -> SourceAttribute {
17 SourceAttribute {
18 id: Some(self.id.clone()),
19 name: self.name.clone(),
20 data_type: self.data_type.clone(),
21 unit: self.unit.clone(),
22 optional: Some(self.optional),
23 }
24 }
25
26 pub fn to_source_attributes(attributes: &[Attribute]) -> Vec<SourceAttribute> {
27 let mut source_attributes = Vec::new();
28
29 for attribute in attributes {
30 source_attributes.push(attribute.to_source_attribute());
31 }
32
33 source_attributes
34 }
35}