Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit e699c34

Browse files
parser: make constant structures iterable
1 parent 2bd1c24 commit e699c34

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/parser/ast/constant.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::slice::Iter;
2+
13
use schemars::JsonSchema;
24
use serde::Deserialize;
35
use serde::Serialize;
@@ -33,6 +35,21 @@ pub struct ConstantStatement {
3335
pub semicolon: Span, // `;`
3436
}
3537

38+
impl ConstantStatement {
39+
pub fn iter(&self) -> Iter<'_, ConstantEntry> {
40+
self.entries.iter()
41+
}
42+
}
43+
44+
impl IntoIterator for ConstantStatement {
45+
type Item = ConstantEntry;
46+
type IntoIter = std::vec::IntoIter<Self::Item>;
47+
48+
fn into_iter(self) -> Self::IntoIter {
49+
self.entries.into_iter()
50+
}
51+
}
52+
3653
impl Node for ConstantStatement {
3754
fn children(&mut self) -> Vec<&mut dyn Node> {
3855
self.entries
@@ -54,6 +71,21 @@ pub struct ClassishConstant {
5471
pub semicolon: Span, // `;`
5572
}
5673

74+
impl ClassishConstant {
75+
pub fn iter(&self) -> Iter<'_, ConstantEntry> {
76+
self.entries.iter()
77+
}
78+
}
79+
80+
impl IntoIterator for ClassishConstant {
81+
type Item = ConstantEntry;
82+
type IntoIter = std::vec::IntoIter<Self::Item>;
83+
84+
fn into_iter(self) -> Self::IntoIter {
85+
self.entries.into_iter()
86+
}
87+
}
88+
5789
impl Node for ClassishConstant {
5890
fn children(&mut self) -> Vec<&mut dyn Node> {
5991
self.entries

0 commit comments

Comments
 (0)