csskit_transform/transform.rs
1use crate::{Transformer, TransformerFeatures};
2use css_parse::{NodeMetadata, NodeWithMetadata};
3
4pub trait Transform<'a, 'ctx, M: NodeMetadata, N: NodeWithMetadata<M>, F: TransformerFeatures<M, N>> {
5 /// Returns true when a subtree described by `metadata` cannot contain anything this transform
6 /// rewrites.
7 ///
8 /// [`Transformer`] asks this of the root node before running the transform at all, and the
9 /// transform asks it of every queryable node it enters, pruning the subtree when it holds.
10 /// Metadata aggregates upwards, so a kind absent from `metadata` is absent from the whole
11 /// subtree: answering `true` for a subtree that does contain such a node silently skips work.
12 fn skips_subtree(metadata: &M) -> bool;
13
14 fn new(transformer: &'ctx Transformer<'a, M, N, F>) -> Self;
15}