microcad_lang/syntax/parameter/
parameter_list.rs1use crate::{ord_map::*, src_ref::*, syntax::*};
7use derive_more::{Deref, DerefMut};
8
9#[derive(Clone, Debug, Default, Deref, DerefMut)]
11pub struct ParameterList(pub Refer<OrdMap<Identifier, Parameter>>);
12
13impl ParameterList {
14 pub fn ids(&self) -> impl Iterator<Item = Identifier> {
16 self.keys().cloned()
17 }
18
19 pub fn contains_key(&self, id: &Identifier) -> bool {
21 self.iter().any(|p| *id == p.id)
22 }
23}
24
25impl SrcReferrer for ParameterList {
26 fn src_ref(&self) -> SrcRef {
27 self.0.src_ref.clone()
28 }
29}
30
31impl std::fmt::Display for ParameterList {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(
34 f,
35 "{}",
36 self.0
37 .iter()
38 .map(|p| p.to_string())
39 .collect::<Vec<_>>()
40 .join(", ")
41 )
42 }
43}
44
45impl TreeDisplay for ParameterList {
46 fn tree_print(&self, f: &mut std::fmt::Formatter, mut depth: TreeState) -> std::fmt::Result {
47 writeln!(f, "{:depth$}ParameterList:", "")?;
48 depth.indent();
49 self.0.iter().try_for_each(|p| p.tree_print(f, depth))
50 }
51}