selectors::parser

Enum Component

source
pub enum Component<Impl: SelectorImpl> {
Show 31 variants Combinator(Combinator), ExplicitAnyNamespace, ExplicitNoNamespace, DefaultNamespace(Impl::NamespaceUrl), Namespace(Impl::NamespacePrefix, Impl::NamespaceUrl), ExplicitUniversalType, LocalName(LocalName<Impl>), ID(Impl::Identifier), Class(Impl::ClassName), AttributeInNoNamespaceExists { local_name: Impl::LocalName, local_name_lower: Impl::LocalName, }, AttributeInNoNamespace { local_name: Impl::LocalName, operator: AttrSelectorOperator, value: Impl::AttrValue, case_sensitivity: ParsedCaseSensitivity, never_matches: bool, }, AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>), Negation(ThinBoxedSlice<Component<Impl>>), FirstChild, LastChild, OnlyChild, Root, Empty, Scope, NthChild(i32, i32), NthLastChild(i32, i32), NthOfType(i32, i32), NthLastOfType(i32, i32), FirstOfType, LastOfType, OnlyOfType, NonTSPseudoClass(Impl::NonTSPseudoClass), Slotted(Selector<Impl>), Part(Box<[Impl::PartName]>), Host(Option<Selector<Impl>>), PseudoElement(Impl::PseudoElement),
}
Expand description

A CSS simple selector or combinator. We store both in the same enum for optimal packing and cache performance, see [1].

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973

Variants§

§

Combinator(Combinator)

§

ExplicitAnyNamespace

§

ExplicitNoNamespace

§

DefaultNamespace(Impl::NamespaceUrl)

§

Namespace(Impl::NamespacePrefix, Impl::NamespaceUrl)

§

ExplicitUniversalType

§

LocalName(LocalName<Impl>)

§

ID(Impl::Identifier)

§

Class(Impl::ClassName)

§

AttributeInNoNamespaceExists

Fields

§local_name: Impl::LocalName
§local_name_lower: Impl::LocalName
§

AttributeInNoNamespace

Fields

§local_name: Impl::LocalName
§value: Impl::AttrValue
§case_sensitivity: ParsedCaseSensitivity
§never_matches: bool
§

AttributeOther(Box<AttrSelectorWithOptionalNamespace<Impl>>)

§

Negation(ThinBoxedSlice<Component<Impl>>)

Pseudo-classes

CSS3 Negation only takes a simple simple selector, but we still need to treat it as a compound selector because it might be a type selector which we represent as a namespace and a localname.

Note: if/when we upgrade this to CSS4, which supports combinators, we need to think about how this should interact with visit_complex_selector, and what the consumers of those APIs should do about the presence of combinators in negation.

§

FirstChild

§

LastChild

§

OnlyChild

§

Root

§

Empty

§

Scope

§

NthChild(i32, i32)

§

NthLastChild(i32, i32)

§

NthOfType(i32, i32)

§

NthLastOfType(i32, i32)

§

FirstOfType

§

LastOfType

§

OnlyOfType

§

NonTSPseudoClass(Impl::NonTSPseudoClass)

§

Slotted(Selector<Impl>)

The ::slotted() pseudo-element:

https://drafts.csswg.org/css-scoping/#slotted-pseudo

The selector here is a compound selector, that is, no combinators.

NOTE(emilio): This should support a list of selectors, but as of this writing no other browser does, and that allows them to put ::slotted() in the rule hash, so we do that too.

See https://github.com/w3c/csswg-drafts/issues/2158

§

Part(Box<[Impl::PartName]>)

The ::part pseudo-element. https://drafts.csswg.org/css-shadow-parts/#part

§

Host(Option<Selector<Impl>>)

The :host pseudo-class:

https://drafts.csswg.org/css-scoping/#host-selector

NOTE(emilio): This should support a list of selectors, but as of this writing no other browser does, and that allows them to put :host() in the rule hash, so we do that too.

See https://github.com/w3c/csswg-drafts/issues/2158

§

PseudoElement(Impl::PseudoElement)

Implementations§

source§

impl<Impl: SelectorImpl> Component<Impl>

source

pub fn is_combinator(&self) -> bool

Returns true if this is a combinator.

source

pub fn as_combinator(&self) -> Option<Combinator>

Returns the value as a combinator if applicable, None otherwise.

Trait Implementations§

source§

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

source§

fn clone(&self) -> Component<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 Component<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 Component<Impl>

source§

fn eq(&self, other: &Component<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 Component<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 Component<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 Component<Impl>
where Impl::NamespaceUrl: Eq, Impl::NamespacePrefix: Eq, Impl::Identifier: Eq, Impl::ClassName: Eq, Impl::LocalName: Eq, Impl::AttrValue: Eq, Impl::NonTSPseudoClass: Eq, Impl::PartName: Eq, Impl::PseudoElement: Eq,

source§

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

Auto Trait Implementations§

§

impl<Impl> Freeze for Component<Impl>

§

impl<Impl> RefUnwindSafe for Component<Impl>

§

impl<Impl> Send for Component<Impl>

§

impl<Impl> Sync for Component<Impl>

§

impl<Impl> Unpin for Component<Impl>

§

impl<Impl> UnwindSafe for Component<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.