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