miden_assembly_syntax/ast/attribute/meta/
list.rs1use alloc::vec::Vec;
2
3use miden_debug_types::{SourceSpan, Spanned};
4
5use super::MetaExpr;
6use crate::ast::Ident;
7
8#[derive(Clone)]
10pub struct MetaList {
11 pub span: SourceSpan,
12 pub name: Ident,
14 pub items: Vec<MetaExpr>,
17}
18
19impl Spanned for MetaList {
20 #[inline(always)]
21 fn span(&self) -> SourceSpan {
22 self.span
23 }
24}
25
26impl MetaList {
27 pub fn new<I>(name: Ident, items: I) -> Self
28 where
29 I: IntoIterator<Item = MetaExpr>,
30 {
31 Self {
32 span: SourceSpan::default(),
33 name,
34 items: items.into_iter().collect(),
35 }
36 }
37
38 pub fn with_span(mut self, span: SourceSpan) -> Self {
39 self.span = span;
40 self
41 }
42
43 pub fn name(&self) -> &str {
45 self.name.as_str()
46 }
47
48 pub fn id(&self) -> Ident {
50 self.name.clone()
51 }
52
53 #[inline]
55 pub fn is_empty(&self) -> bool {
56 self.items.is_empty()
57 }
58
59 #[inline]
61 pub fn len(&self) -> usize {
62 self.items.len()
63 }
64
65 #[inline]
67 pub fn as_slice(&self) -> &[MetaExpr] {
68 self.items.as_slice()
69 }
70
71 #[inline]
73 pub fn as_mut_slice(&mut self) -> &mut [MetaExpr] {
74 self.items.as_mut_slice()
75 }
76}
77
78impl Eq for MetaList {}
79
80impl PartialEq for MetaList {
81 fn eq(&self, other: &Self) -> bool {
82 self.name == other.name && self.items == other.items
83 }
84}
85
86impl PartialOrd for MetaList {
87 #[inline]
88 fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
89 Some(self.cmp(other))
90 }
91}
92
93impl Ord for MetaList {
94 fn cmp(&self, other: &Self) -> core::cmp::Ordering {
95 self.name.cmp(&other.name).then_with(|| self.items.cmp(&other.items))
96 }
97}
98
99impl core::hash::Hash for MetaList {
100 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
101 self.name.hash(state);
102 self.items.hash(state);
103 }
104}