css_parse/traits/
node_metadata.rs

1/// Aggregated metadata for nodes, that can propagate up a node tree.
2pub trait NodeMetadata: Sized + Copy + Default {
3	/// Merges another NodeMetadata into this one, returning the result.
4	fn merge(self, other: Self) -> Self;
5
6	/// Sets the size of this metadata (e.g., number of declarations, selector list length).
7	/// Default implementation is a no-op for metadata types that don't track size.
8	fn with_size(self, _size: u16) -> Self {
9		self
10	}
11}
12
13/// A Node that has NodeMetadata
14pub trait NodeWithMetadata<M: NodeMetadata> {
15	/// Returns the metadata contributed by this node itself, not including children.
16	/// Most nodes don't contribute metadata, so can simply return `M::default()`.
17	/// Nodes like StyleRule or AtRules should return their own node kind flags here.
18	fn self_metadata(&self) -> M {
19		M::default()
20	}
21
22	/// Returns the complete aggregated metadata for this node (self + children).
23	/// Default implementation merges children's metadata with self_metadata().
24	fn metadata(&self) -> M;
25}
26
27// Stub implementation allowing tests to use () for M
28impl NodeMetadata for () {
29	fn merge(self, _: Self) -> Self {}
30}