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>
impl<Impl: SelectorImpl> Selector<Impl>
pub fn specificity(&self) -> u32
pub fn has_pseudo_element(&self) -> bool
pub fn is_slotted(&self) -> bool
pub fn is_part(&self) -> bool
pub fn parts(&self) -> Option<&[Impl::PartName]>
pub fn pseudo_element(&self) -> Option<&Impl::PseudoElement>
sourcepub fn is_universal(&self) -> bool
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
sourcepub fn iter(&self) -> SelectorIter<'_, Impl> ⓘ
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.
sourcepub fn is_featureless_host_selector_or_pseudo_element(&self) -> bool
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.
sourcepub fn iter_from(&self, offset: usize) -> SelectorIter<'_, Impl> ⓘ
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.
sourcepub fn combinator_at_match_order(&self, index: usize) -> Combinator
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.
sourcepub fn iter_raw_match_order(&self) -> Iter<'_, Component<Impl>>
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).
sourcepub fn combinator_at_parse_order(&self, index: usize) -> Combinator
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.
sourcepub fn iter_raw_parse_order_from(
&self,
offset: usize,
) -> Rev<Iter<'_, Component<Impl>>>
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
.
sourcepub fn thin_arc_heap_ptr(&self) -> *const c_void
pub fn thin_arc_heap_ptr(&self) -> *const c_void
Returns the address on the heap of the ThinArc for memory reporting.
Trait Implementations§
source§impl<Impl: SelectorImpl> Debug for Selector<Impl>
impl<Impl: SelectorImpl> Debug for Selector<Impl>
source§impl<Impl: SelectorImpl> ToCss for Selector<Impl>
impl<Impl: SelectorImpl> ToCss for Selector<Impl>
source§impl<Impl: SelectorImpl> Visit for Selector<Impl>where
Impl::NonTSPseudoClass: Visit<Impl = Impl>,
impl<Impl: SelectorImpl> Visit for Selector<Impl>where
Impl::NonTSPseudoClass: Visit<Impl = Impl>,
impl<Impl: Eq + SelectorImpl> Eq for Selector<Impl>
impl<Impl: SelectorImpl> StructuralPartialEq for Selector<Impl>
Auto Trait Implementations§
impl<Impl> Freeze for Selector<Impl>
impl<Impl> RefUnwindSafe for Selector<Impl>where
<Impl as SelectorImpl>::NamespaceUrl: RefUnwindSafe,
<Impl as SelectorImpl>::NamespacePrefix: RefUnwindSafe,
<Impl as SelectorImpl>::Identifier: RefUnwindSafe,
<Impl as SelectorImpl>::ClassName: RefUnwindSafe,
<Impl as SelectorImpl>::LocalName: RefUnwindSafe,
<Impl as SelectorImpl>::AttrValue: RefUnwindSafe,
<Impl as SelectorImpl>::NonTSPseudoClass: RefUnwindSafe,
<Impl as SelectorImpl>::PseudoElement: RefUnwindSafe,
<Impl as SelectorImpl>::PartName: RefUnwindSafe,
impl<Impl> Send for Selector<Impl>where
<Impl as SelectorImpl>::NamespaceUrl: Sync + Send,
<Impl as SelectorImpl>::NamespacePrefix: Sync + Send,
<Impl as SelectorImpl>::Identifier: Sync + Send,
<Impl as SelectorImpl>::ClassName: Sync + Send,
<Impl as SelectorImpl>::LocalName: Sync + Send,
<Impl as SelectorImpl>::AttrValue: Sync + Send,
<Impl as SelectorImpl>::NonTSPseudoClass: Sync + Send,
<Impl as SelectorImpl>::PseudoElement: Sync + Send,
<Impl as SelectorImpl>::PartName: Sync + Send,
impl<Impl> Sync for Selector<Impl>where
<Impl as SelectorImpl>::NamespaceUrl: Sync + Send,
<Impl as SelectorImpl>::NamespacePrefix: Sync + Send,
<Impl as SelectorImpl>::Identifier: Sync + Send,
<Impl as SelectorImpl>::ClassName: Sync + Send,
<Impl as SelectorImpl>::LocalName: Sync + Send,
<Impl as SelectorImpl>::AttrValue: Sync + Send,
<Impl as SelectorImpl>::NonTSPseudoClass: Sync + Send,
<Impl as SelectorImpl>::PseudoElement: Sync + Send,
<Impl as SelectorImpl>::PartName: Sync + Send,
impl<Impl> Unpin for Selector<Impl>
impl<Impl> UnwindSafe for Selector<Impl>where
<Impl as SelectorImpl>::NamespaceUrl: RefUnwindSafe,
<Impl as SelectorImpl>::NamespacePrefix: RefUnwindSafe,
<Impl as SelectorImpl>::Identifier: RefUnwindSafe,
<Impl as SelectorImpl>::ClassName: RefUnwindSafe,
<Impl as SelectorImpl>::LocalName: RefUnwindSafe,
<Impl as SelectorImpl>::AttrValue: RefUnwindSafe,
<Impl as SelectorImpl>::NonTSPseudoClass: RefUnwindSafe,
<Impl as SelectorImpl>::PseudoElement: RefUnwindSafe,
<Impl as SelectorImpl>::PartName: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)