Struct selectors::builder::SelectorBuilder

source ·
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> Freeze for SelectorBuilder<Impl>

§

impl<Impl> RefUnwindSafe for SelectorBuilder<Impl>

§

impl<Impl> Send for SelectorBuilder<Impl>

§

impl<Impl> Sync for SelectorBuilder<Impl>

§

impl<Impl> Unpin for SelectorBuilder<Impl>

§

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