selectors::parser

Struct Selector

source
pub struct Selector<Impl: SelectorImpl>(/* private fields */);
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§

source§

impl<Impl: SelectorImpl> Selector<Impl>

source

pub fn specificity(&self) -> u32

source

pub fn has_pseudo_element(&self) -> bool

source

pub fn is_slotted(&self) -> bool

source

pub fn is_part(&self) -> bool

source

pub fn parts(&self) -> Option<&[Impl::PartName]>

source

pub fn pseudo_element(&self) -> Option<&Impl::PseudoElement>

source

pub fn is_universal(&self) -> bool

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

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

source

pub fn iter(&self) -> SelectorIter<'_, Impl>

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.

source

pub fn is_featureless_host_selector_or_pseudo_element(&self) -> bool

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

source

pub fn iter_from(&self, offset: usize) -> SelectorIter<'_, Impl>

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

source

pub fn combinator_at_match_order(&self, index: usize) -> Combinator

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

source

pub fn iter_raw_match_order(&self) -> Iter<'_, Component<Impl>>

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

source

pub fn combinator_at_parse_order(&self, index: usize) -> Combinator

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

source

pub fn iter_raw_parse_order_from( &self, offset: usize, ) -> Rev<Iter<'_, Component<Impl>>>

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

source

pub fn len(&self) -> usize

Returns count of simple selectors and combinators in the Selector.

source

pub fn thin_arc_heap_ptr(&self) -> *const c_void

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

source§

impl<Impl: SelectorImpl> Selector<Impl>

source

pub fn parse<'i, 't, P>( parser: &P, input: &mut CssParser<'i, 't>, ) -> Result<Self, ParseError<'i, P::Error>>
where P: Parser<'i, Impl = Impl>,

Parse a selector, without any pseudo-element.

Trait Implementations§

source§

impl<Impl: Clone + SelectorImpl> Clone for Selector<Impl>

source§

fn clone(&self) -> Selector<Impl>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Impl: SelectorImpl> Debug for Selector<Impl>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Impl: PartialEq + SelectorImpl> PartialEq for Selector<Impl>

source§

fn eq(&self, other: &Selector<Impl>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<Impl: SelectorImpl> ToCss for Selector<Impl>

source§

fn to_css<W>(&self, dest: &mut W) -> Result
where W: Write,

Serialize self in CSS syntax, writing to dest.
source§

fn to_css_string(&self) -> String

Serialize self in CSS syntax and return a string. Read more
source§

impl<Impl: SelectorImpl> Visit for Selector<Impl>
where Impl::NonTSPseudoClass: Visit<Impl = Impl>,

source§

type Impl = Impl

The type parameter of selector component types.
source§

fn visit<V>(&self, visitor: &mut V) -> bool
where V: SelectorVisitor<Impl = Impl>,

Traverse selector components inside self. Read more
source§

impl<Impl: Eq + SelectorImpl> Eq for Selector<Impl>

source§

impl<Impl: SelectorImpl> StructuralPartialEq for Selector<Impl>

Auto Trait Implementations§

§

impl<Impl> Freeze for Selector<Impl>

§

impl<Impl> RefUnwindSafe for Selector<Impl>

§

impl<Impl> Send for Selector<Impl>

§

impl<Impl> Sync for Selector<Impl>

§

impl<Impl> Unpin for Selector<Impl>

§

impl<Impl> UnwindSafe for Selector<Impl>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.