pub struct Selector {
pub parts: Vec<SimpleSelector>,
pub combinators: Vec<Combinator>,
}Expand description
A compound selector — one or more SimpleSelectors joined by
Combinators. parts.len() == combinators.len() + 1.
parts[0] is the leftmost (ancestor/sibling) end; parts.last()
is the subject that is matched against the target node.
For a simple flat selector (no combinator) parts has one entry and
combinators is empty.
Fields§
§parts: Vec<SimpleSelector>§combinators: Vec<Combinator>Implementations§
Source§impl Selector
impl Selector
Sourcepub fn specificity(&self) -> u32
pub fn specificity(&self) -> u32
CSS specificity: sum of each part’s specificity. Combinators contribute 0.
Sourcepub fn matches(
&self,
target: &Node<'_>,
ancestors: &[Node<'_>],
prev_siblings: &[Node<'_>],
state: Option<PseudoClass>,
) -> bool
pub fn matches( &self, target: &Node<'_>, ancestors: &[Node<'_>], prev_siblings: &[Node<'_>], state: Option<PseudoClass>, ) -> bool
Match against target given its ancestors (root → parent,
exclusive of the target) and prev_siblings (oldest → the
immediately preceding sibling, exclusive of the target).
state is the pseudo-class active on the target; ancestors are
always matched without pseudo-class.
§Sibling combinator limitation (v1)
AdjacentSibling and GeneralSibling match the sibling against
prev_siblings. If the rule continues leftward past the sibling
combinator into a Descendant or Child step (e.g.
.grandparent > .prev + .target), the next combinator is evaluated
against the target’s own ancestors rather than the sibling’s
ancestors. This may false-negative when the continuation requires
introspecting the sibling’s subtree context. Fully recursive
sibling-vs-ancestor context requires the adapter to supply
sibling-of-sibling data, which is out of scope for v1. Chained
sibling combinators (.a + .b + .c) walk the prev-sibling list
correctly and do not hit this limitation.