Struct selectors::parser::Selector

source ·
#[repr(transparent)]
pub struct Selector<Impl: SelectorImpl>(ThinArc<SpecificityAndFlags, Component<Impl>>);
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.

Tuple Fields§

§0: ThinArc<SpecificityAndFlags, Component<Impl>>

Implementations§

source§

impl<Impl: SelectorImpl> Selector<Impl>

source

pub fn mark_as_intentionally_leaked(&self)

See Arc::mark_as_intentionally_leaked

source

fn ampersand() -> Self

source

fn scope() -> Self

source

pub fn specificity(&self) -> u32

source

pub(crate) fn flags(&self) -> SelectorFlags

source

pub fn has_pseudo_element(&self) -> bool

source

pub fn has_parent_selector(&self) -> bool

source

pub fn has_scope_selector(&self) -> bool

source

pub fn is_slotted(&self) -> bool

source

pub fn is_part(&self) -> bool

source

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

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 iter_skip_relative_selector_anchor(&self) -> SelectorIter<'_, Impl>

Same as iter(), but skips RelativeSelectorAnchor and its associated combinator.

source

pub fn matches_featureless_host_selector_or_pseudo_element( &self, ) -> FeaturelessHostMatches

Whether this selector matches a featureless shadow host, 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(crate) fn from_vec( vec: Vec<Component<Impl>>, specificity: u32, flags: SelectorFlags, ) -> Self

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

source

fn into_data(self) -> ThinArc<SpecificityAndFlags, Component<Impl>>

source

pub fn replace_parent_selector(&self, parent: &SelectorList<Impl>) -> Self

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

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

Traverse selector components inside self.

Implementations of this method should call SelectorVisitor methods or other impls of Visit as appropriate based on the fields of Self.

A return value of false indicates terminating the traversal. It should be propagated with an early return. On the contrary, true indicates that all fields of self have been traversed:

if !visitor.visit_simple_selector(&self.some_simple_selector) {
    return false;
}
if !self.some_component.visit(visitor) {
    return false;
}
true
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.

source

pub fn new_invalid(s: &str) -> Self

source

pub fn is_rightmost(&self, offset: usize) -> bool

Is the compound starting at the offset the subject compound, or referring to its 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

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

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

This method 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> ToShmem for Selector<Impl>

source§

fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> Result<Self>

Clones this value into a form suitable for writing into a SharedMemoryBuilder. 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> 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,

§

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>,

§

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>,

§

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.