cairo_lang_syntax/node/
element_list.rsuse std::marker::PhantomData;
use super::SyntaxGroup;
use crate::node::{SyntaxNode, TypedSyntaxNode};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct ElementList<T: TypedSyntaxNode, const STEP: usize> {
pub node: SyntaxNode,
phantom: PhantomData<T>,
}
impl<T: TypedSyntaxNode, const STEP: usize> ElementList<T, STEP> {
pub fn new(node: SyntaxNode) -> Self {
Self { node, phantom: PhantomData {} }
}
pub fn elements(&self, db: &dyn SyntaxGroup) -> Vec<T> {
db.get_children(self.node.clone())
.iter()
.step_by(STEP)
.map(|x| T::from_syntax_node(db, x.clone()))
.collect()
}
pub fn has_tail(&self, db: &dyn SyntaxGroup) -> bool {
db.get_children(self.node.clone()).iter().len() % STEP != 0
}
}