moduforge_runtime/
mark.rs1use std::collections::HashMap;
2
3use moduforge_core::model::{mark_type::MarkSpec, schema::AttributeSpec};
4
5#[derive(Clone, PartialEq, Debug, Eq)]
6pub struct Mark {
7 pub name: String,
8 pub r#type: MarkSpec,
9}
10
11impl Mark {
12 pub fn new(
13 name: &str,
14 spec: MarkSpec,
15 ) -> Mark {
16 Mark { name: name.to_string(), r#type: spec }
17 }
18 pub fn set_name(
19 &mut self,
20 name: &str,
21 ) -> &mut Self {
22 self.name = name.to_string();
23 self
24 }
25 pub fn get_name(&self) -> &str {
26 &self.name
27 }
28
29 pub fn set_attrs(
30 &mut self,
31 attrs: HashMap<String, AttributeSpec>,
32 ) -> &mut Self {
33 self.r#type.attrs = Some(attrs);
34 self
35 }
36 pub fn set_attr(
37 &mut self,
38 name: &str,
39 default: Option<String>,
40 ) -> &mut Self {
41 match &mut self.r#type.attrs {
42 Some(map) => {
43 map.insert(name.to_string(), AttributeSpec { default });
44 },
45 None => {
46 let mut new_map = HashMap::new();
47 new_map.insert(name.to_string(), AttributeSpec { default });
48 self.r#type.attrs = Some(new_map);
49 },
50 }
51 self
52 }
53 pub fn set_desc(
54 &mut self,
55 desc: &str,
56 ) -> &mut Self {
57 self.r#type.desc = Some(desc.to_string());
58 self
59 }
60}