pub struct QueryBuilder<'query> {
pub states: Vec<Transition<'query>>,
pub selection: Vec<QuerySection<'query>>,
}Expand description
An in-progress query being assembled via a builder pattern.
You typically don’t construct a QueryBuilder directly; instead,
start with Query::all or Query::first and then chain further
selectors with .all(), .first(),
or .then(). Finalise with .build()
to produce a Query.
§Example
use scah::{Query, Save};
let query = Query::all("main > section", Save::all())
.then(|ctx| [
ctx.all("> a[href]", Save::all()),
ctx.all("div a", Save::only_text_content()),
])
.build();Fields§
§states: Vec<Transition<'query>>Internal automaton transitions (compiled selector segments).
selection: Vec<QuerySection<'query>>Internal ordered list of query sections.
Implementations§
Source§impl<'query> QueryBuilder<'query>
impl<'query> QueryBuilder<'query>
Sourcepub fn all(self, query: &'query str, save: Save) -> Self
pub fn all(self, query: &'query str, save: Save) -> Self
Append a child selector that matches all occurrences.
The new selector is scoped to elements that already matched the previous selector in the chain.
Sourcepub fn first(self, query: &'query str, save: Save) -> Self
pub fn first(self, query: &'query str, save: Save) -> Self
Append a child selector that matches only the first occurrence.
Enables early-exit optimisation for this branch of the query tree.
pub fn append(&mut self, parent: usize, other: Self)
Sourcepub fn then<F, I>(self, func: F) -> Self
pub fn then<F, I>(self, func: F) -> Self
Branch into multiple child queries using a closure.
The closure receives a QueryFactory that can create new
sub-queries. Each sub-query is scoped to run only within elements
matched by the current (most recently added) selector.
This is the key mechanism for structured querying; extracting hierarchical data relationships in a single streaming pass.
§Example
use scah::{Query, Save};
let query = Query::all("article", Save::none())
.then(|article| [
article.first("h1", Save::only_text_content()),
article.all("a[href]", Save::all()),
])
.build();Trait Implementations§
Source§impl<'query> Clone for QueryBuilder<'query>
impl<'query> Clone for QueryBuilder<'query>
Source§fn clone(&self) -> QueryBuilder<'query>
fn clone(&self) -> QueryBuilder<'query>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more