microcad_lang/model/attribute/
attributes.rs1use derive_more::{Deref, DerefMut};
7
8use crate::model::*;
9use microcad_lang_base::Identifier;
10
11#[derive(Clone, Debug, Default, Deref, DerefMut)]
18pub struct Attributes(pub Vec<Attribute>);
19
20impl AttributesAccess for Attributes {
21 fn get_attributes_by_id(&self, id: &Identifier) -> Vec<Attribute> {
22 self.iter()
23 .filter(|attribute| attribute.id() == *id)
24 .cloned()
25 .collect()
26 }
27}
28
29impl FromIterator<Attribute> for Attributes {
30 fn from_iter<T: IntoIterator<Item = Attribute>>(iter: T) -> Self {
31 Self(iter.into_iter().collect())
32 }
33}
34
35impl TreeDisplay for Attributes {
36 fn tree_print(&self, f: &mut std::fmt::Formatter, depth: TreeState) -> std::fmt::Result {
37 self.iter()
38 .try_for_each(|attribute| writeln!(f, "{:depth$}{attribute}", ""))
39 }
40}