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.
4 fn merge(&mut self, other: &Self);
5}
6
7/// A Node that has NodeMetadata
8pub trait NodeWithMetadata<M: NodeMetadata> {
9 /// Returns the metadata contributed by this node itself plus and child meta.
10 /// Most nodes don't contribute metadata, so can simply return `child`.
11 /// Other nodes may want to alter the metadata; supplying their own modifications
12 /// to initial.
13 fn self_metadata(&self, initial: M) -> M {
14 initial
15 }
16
17 /// Returns the complete aggregated metadata for this node (self + children)
18 fn metadata(&self) -> M;
19}
20
21// Stub implementation allowing tests to use () for M
22impl NodeMetadata for () {
23 fn merge(&mut self, _: &Self) {}
24}