use crate::{
CursorSink, DeclarationOrBad, DeclarationValue, NodeMetadata, NodeWithMetadata, SemanticEq, Span, ToCursors, ToSpan,
};
use bumpalo::collections::Vec;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(transparent))]
pub struct DeclarationGroup<'a, D, M>
where
D: DeclarationValue<'a, M>,
M: NodeMetadata,
{
pub declarations: Vec<'a, DeclarationOrBad<'a, D, M>>,
}
impl<'a, D, M> ToCursors for DeclarationGroup<'a, D, M>
where
D: DeclarationValue<'a, M> + ToCursors,
M: NodeMetadata,
{
fn to_cursors(&self, s: &mut impl CursorSink) {
for decl in &self.declarations {
decl.to_cursors(s);
}
}
}
impl<'a, D, M> ToSpan for DeclarationGroup<'a, D, M>
where
D: DeclarationValue<'a, M> + ToSpan,
M: NodeMetadata,
{
fn to_span(&self) -> Span {
self.declarations.to_span()
}
}
impl<'a, D, M> SemanticEq for DeclarationGroup<'a, D, M>
where
D: DeclarationValue<'a, M>,
M: NodeMetadata,
{
fn semantic_eq(&self, other: &Self) -> bool {
self.declarations.semantic_eq(&other.declarations)
}
}
impl<'a, D, M> NodeWithMetadata<M> for DeclarationGroup<'a, D, M>
where
D: DeclarationValue<'a, M>,
M: NodeMetadata,
{
fn metadata(&self) -> M {
let mut meta = M::default();
for decl in &self.declarations {
meta = meta.merge(decl.metadata());
}
meta
}
}