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