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>
impl<Impl: SelectorImpl> SelectorBuilder<Impl>
sourcepub fn push_simple_selector(&mut self, ss: Component<Impl>)
pub fn push_simple_selector(&mut self, ss: Component<Impl>)
Pushes a simple selector onto the current compound selector.
sourcepub fn push_combinator(&mut self, c: Combinator)
pub fn push_combinator(&mut self, c: Combinator)
Completes the current compound selector and starts a new one, delimited by the given combinator.
fn reverse_last_compound(&mut self)
sourcepub fn has_combinators(&self) -> bool
pub fn has_combinators(&self) -> bool
Returns true if combinators have ever been pushed to this builder.
sourcepub fn build(
&mut self,
parse_relative: ParseRelative,
) -> ThinArc<SpecificityAndFlags, Component<Impl>>
pub fn build( &mut self, parse_relative: ParseRelative, ) -> ThinArc<SpecificityAndFlags, Component<Impl>>
Consumes the builder, producing a Selector.
sourcepub(crate) fn build_with_specificity_and_flags(
&mut self,
spec: SpecificityAndFlags,
parse_relative: ParseRelative,
) -> ThinArc<SpecificityAndFlags, Component<Impl>>
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.