pub struct SelectorBuilder<Impl: SelectorImpl> {
    components: SmallVec<[Component<Impl>; 32]>,
    last_compound_start: Option<usize>,
}
Expand description

Top-level SelectorBuilder struct. This should be stack-allocated by the consumer and never moved (because it contains a lot of inline data that would be slow to memmove).

After instantiation, callers may call the push_simple_selector() and push_combinator() methods to append selector data as it is encountered (from left to right). Once the process is complete, callers should invoke build(), which transforms the contents of the SelectorBuilder into a heap- allocated Selector and leaves the builder in a drained state.

Fields§

§components: SmallVec<[Component<Impl>; 32]>

The entire sequence of components. We make this large because the result of parsing a selector is fed into a new Arc-ed allocation, so any spilled vec would be a wasted allocation. Also, Components are large enough that we don’t have much cache locality benefit from reserving stack space for fewer of them.

§last_compound_start: Option<usize>

Implementations§

source§

impl<Impl: SelectorImpl> SelectorBuilder<Impl>

source

pub fn push_simple_selector(&mut self, ss: Component<Impl>)

Pushes a simple selector onto the current compound selector.

source

pub fn push_combinator(&mut self, c: Combinator)

Completes the current compound selector and starts a new one, delimited by the given combinator.

source

fn reverse_last_compound(&mut self)

source

pub fn has_combinators(&self) -> bool

Returns true if combinators have ever been pushed to this builder.

source

pub fn build( &mut self, parse_relative: ParseRelative ) -> ThinArc<SpecificityAndFlags, Component<Impl>>

Consumes the builder, producing a Selector.

source

pub(crate) fn build_with_specificity_and_flags( &mut self, spec: SpecificityAndFlags, parse_relative: ParseRelative ) -> ThinArc<SpecificityAndFlags, Component<Impl>>

Builds with an explicit SpecificityAndFlags. This is separated from build() so that unit tests can pass an explicit specificity.

Trait Implementations§

source§

impl<Impl: Debug + SelectorImpl> Debug for SelectorBuilder<Impl>

source§

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

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

impl<Impl: SelectorImpl> Default for SelectorBuilder<Impl>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<Impl: SelectorImpl> Push<Component<Impl>> for SelectorBuilder<Impl>

source§

fn push(&mut self, value: Component<Impl>)

Push a value into self.

Auto Trait Implementations§

§

impl<Impl> RefUnwindSafe for SelectorBuilder<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 SelectorBuilder<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 SelectorBuilder<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 SelectorBuilder<Impl>where <Impl as SelectorImpl>::AttrValue: Unpin, <Impl as SelectorImpl>::Identifier: Unpin, <Impl as SelectorImpl>::LocalName: Unpin, <Impl as SelectorImpl>::NamespacePrefix: Unpin, <Impl as SelectorImpl>::NamespaceUrl: Unpin, <Impl as SelectorImpl>::NonTSPseudoClass: Unpin, <Impl as SelectorImpl>::PseudoElement: Unpin,

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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, U> TryFrom<U> for Twhere 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 Twhere 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.