Struct selectors::parser::Selector

source ·
pub struct Selector<Impl: SelectorImpl>(_);
Expand description

A Selector stores a sequence of simple selectors and combinators. The iterator classes allow callers to iterate at either the raw sequence level or at the level of sequences of simple selectors separated by combinators. Most callers want the higher-level iterator.

We store compound selectors internally right-to-left (in matching order). Additionally, we invert the order of top-level compound selectors so that each one matches left-to-right. This is because matching namespace, local name, id, and class are all relatively cheap, whereas matching pseudo-classes might be expensive (depending on the pseudo-class). Since authors tend to put the pseudo-classes on the right, it’s faster to start matching on the left.

This reordering doesn’t change the semantics of selector matching, and we handle it in to_css to make it invisible to serialization.

Implementations§

Whether this selector (pseudo-element part excluded) matches every element.

Used for “pre-computed” pseudo-elements in components/style/stylist.rs

Returns an iterator over this selector in matching order (right-to-left). When a combinator is reached, the iterator will return None, and next_sequence() may be called to continue to the next sequence.

Whether this selector is a featureless :host selector, with no combinators to the left, and optionally has a pseudo-element to the right.

Returns an iterator over this selector in matching order (right-to-left), skipping the rightmost |offset| Components.

Returns the combinator at index index (zero-indexed from the right), or panics if the component is not a combinator.

Returns an iterator over the entire sequence of simple selectors and combinators, in matching order (from right to left).

Returns the combinator at index index (zero-indexed from the left), or panics if the component is not a combinator.

Returns an iterator over the sequence of simple selectors and combinators, in parse order (from left to right), starting from offset.

Creates a Selector from a vec of Components, specified in parse order. Used in tests.

Returns count of simple selectors and combinators in the Selector.

Returns the address on the heap of the ThinArc for memory reporting.

Parse a selector, without any pseudo-element.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize self in CSS syntax, writing to dest.
Serialize self in CSS syntax and return a string. Read more
The type parameter of selector component types.
Traverse selector components inside self. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.