oca_bundle_semantics/state/oca/overlay/
attribute_mapping.rs1use crate::state::{attribute::Attribute, oca::Overlay};
2use oca_ast_semantics::ast::OverlayType;
3use serde::{Deserialize, Serialize};
4use std::any::Any;
5use std::collections::BTreeMap;
6
7use said::derivation::HashFunctionCode;
8use said::{sad::SerializationFormats, sad::SAD};
9
10#[derive(SAD, Serialize, Deserialize, Debug, Clone)]
11pub struct AttributeMappingOverlay {
12 #[said]
13 #[serde(rename = "d")]
14 said: Option<said::SelfAddressingIdentifier>,
15 #[serde(rename = "type")]
16 overlay_type: OverlayType,
17 capture_base: Option<said::SelfAddressingIdentifier>,
18 pub attribute_mapping: BTreeMap<String, String>,
19}
20
21impl Overlay for AttributeMappingOverlay {
22 fn as_any(&self) -> &dyn Any {
23 self
24 }
25 fn capture_base(&self) -> &Option<said::SelfAddressingIdentifier> {
26 &self.capture_base
27 }
28 fn set_capture_base(&mut self, said: &said::SelfAddressingIdentifier) {
29 self.capture_base = Some(said.clone());
30 }
31 fn said(&self) -> &Option<said::SelfAddressingIdentifier> {
32 &self.said
33 }
34 fn overlay_type(&self) -> &OverlayType {
35 &self.overlay_type
36 }
37 fn attributes(&self) -> Vec<&String> {
38 self.attribute_mapping.keys().collect::<Vec<&String>>()
39 }
40
41 fn add(&mut self, _attribute: &Attribute) {
42 }
49}
50impl AttributeMappingOverlay {
51 pub fn new() -> Box<Self> {
52 let overlay_version = "1.1".to_string();
53 Box::new(Self {
54 capture_base: None,
55 said: None,
56 overlay_type: OverlayType::AttributeMapping(overlay_version),
57 attribute_mapping: BTreeMap::new(),
58 })
59 }
60}