Struct selectors::parser::Selector[][src]

pub struct Selector<Impl: SelectorImpl>(_);

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

impl<Impl: SelectorImpl> Selector<Impl>[src]

pub fn specificity(&self) -> u32[src]

pub fn has_pseudo_element(&self) -> bool[src]

pub fn is_slotted(&self) -> bool[src]

pub fn is_part(&self) -> bool[src]

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

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

pub fn is_universal(&self) -> bool[src]

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

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

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

Notable traits for SelectorIter<'a, Impl>

impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> type Item = &'a Component<Impl>;
[src]

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.

pub fn is_featureless_host_selector_or_pseudo_element(&self) -> bool[src]

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

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

Notable traits for SelectorIter<'a, Impl>

impl<'a, Impl: SelectorImpl> Iterator for SelectorIter<'a, Impl> type Item = &'a Component<Impl>;
[src]

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

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

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

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

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

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

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

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

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

pub fn len(&self) -> usize[src]

Returns count of simple selectors and combinators in the Selector.

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

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

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

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

impl<Impl: SelectorImpl> Selector<Impl>[src]

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>, 
[src]

Parse a selector, without any pseudo-element.

Trait Implementations

impl<Impl: Clone + SelectorImpl> Clone for Selector<Impl>[src]

impl<Impl: SelectorImpl> Debug for Selector<Impl>[src]

impl<Impl: Eq + SelectorImpl> Eq for Selector<Impl>[src]

impl<Impl: PartialEq + SelectorImpl> PartialEq<Selector<Impl>> for Selector<Impl>[src]

impl<Impl: SelectorImpl> StructuralEq for Selector<Impl>[src]

impl<Impl: SelectorImpl> StructuralPartialEq for Selector<Impl>[src]

impl<Impl: SelectorImpl> ToCss for Selector<Impl>[src]

Auto Trait Implementations

impl<Impl> RefUnwindSafe for Selector<Impl> where
    <Impl as SelectorImpl>::AttrValue: RefUnwindSafe,
    <Impl as SelectorImpl>::Identifier: RefUnwindSafe,
    <Impl as SelectorImpl>::LocalName: RefUnwindSafe,
    <Impl as SelectorImpl>::NamespacePrefix: RefUnwindSafe,
    <Impl as SelectorImpl>::NamespaceUrl: RefUnwindSafe,
    <Impl as SelectorImpl>::NonTSPseudoClass: RefUnwindSafe,
    <Impl as SelectorImpl>::PseudoElement: RefUnwindSafe

impl<Impl> Send for Selector<Impl> where
    <Impl as SelectorImpl>::AttrValue: Send + Sync,
    <Impl as SelectorImpl>::Identifier: Send + Sync,
    <Impl as SelectorImpl>::LocalName: Send + Sync,
    <Impl as SelectorImpl>::NamespacePrefix: Send + Sync,
    <Impl as SelectorImpl>::NamespaceUrl: Send + Sync,
    <Impl as SelectorImpl>::NonTSPseudoClass: Send + Sync,
    <Impl as SelectorImpl>::PseudoElement: Send + Sync

impl<Impl> Sync for Selector<Impl> where
    <Impl as SelectorImpl>::AttrValue: Send + Sync,
    <Impl as SelectorImpl>::Identifier: Send + Sync,
    <Impl as SelectorImpl>::LocalName: Send + Sync,
    <Impl as SelectorImpl>::NamespacePrefix: Send + Sync,
    <Impl as SelectorImpl>::NamespaceUrl: Send + Sync,
    <Impl as SelectorImpl>::NonTSPseudoClass: Send + Sync,
    <Impl as SelectorImpl>::PseudoElement: Send + Sync

impl<Impl> Unpin for Selector<Impl>

impl<Impl> UnwindSafe for Selector<Impl> where
    <Impl as SelectorImpl>::AttrValue: RefUnwindSafe,
    <Impl as SelectorImpl>::Identifier: RefUnwindSafe,
    <Impl as SelectorImpl>::LocalName: RefUnwindSafe,
    <Impl as SelectorImpl>::NamespacePrefix: RefUnwindSafe,
    <Impl as SelectorImpl>::NamespaceUrl: RefUnwindSafe,
    <Impl as SelectorImpl>::NonTSPseudoClass: RefUnwindSafe,
    <Impl as SelectorImpl>::PseudoElement: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.