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