pub struct Store<'html, 'query> {
pub elements: Arena<Element<'html>, ElementId>,
pub attributes: Arena<Attribute<'html>, AttributeId>,
pub queries: Arena<QueryNode<'query>, QueryId>,
pub text_content: TextContent,
}Expand description
The result set returned by parse.
A Store is an arena-based container that holds all elements, attributes,
and text content captured during parsing. You query it by CSS selector
string using Store::get.
§Example
use scah::{Query, Save, parse};
let html = "<div><a href='x'>Link1</a><a href='y'>Link2</a></div>";
let queries = &[Query::all("a", Save::all()).build()];
let store = parse(html, queries);
// Retrieve all matched <a> elements
let anchors: Vec<_> = store.get("a").unwrap().collect();
assert_eq!(anchors.len(), 2);
// Access attributes
assert_eq!(anchors[0].attribute(&store, "href"), Some("x"));Fields§
§elements: Arena<Element<'html>, ElementId>Arena of matched elements.
attributes: Arena<Attribute<'html>, AttributeId>Arena of attributes belonging to matched elements.
queries: Arena<QueryNode<'query>, QueryId>Arena of query nodes that link selectors to their matched elements.
text_content: TextContentAccumulated text-content buffer shared by all elements.
Implementations§
Source§impl<'html, 'query: 'html> Store<'html, 'query>
impl<'html, 'query: 'html> Store<'html, 'query>
pub fn with_capacity(capacity: usize) -> Self
Sourcepub fn get(
&'html self,
query: &str,
) -> Option<impl Iterator<Item = &'html Element<'html>>>
pub fn get( &'html self, query: &str, ) -> Option<impl Iterator<Item = &'html Element<'html>>>
Look up all elements that matched a given CSS selector string.
The query parameter must be the exact same string used when
building the Query (e.g. "main > section > a[href]").
Returns None if no elements were matched by any query, or if
the given selector string was not part of the executed queries.
§Example
use scah::{Query, Save, parse};
let html = "<ul><li>A</li><li>B</li></ul>";
let queries = &[Query::all("li", Save::only_text_content()).build()];
let store = parse(html, queries);
for li in store.get("li").unwrap() {
println!("{}", li.text_content(&store).unwrap_or_default());
}pub fn push( &mut self, from: ElementId, selection: &QuerySection<'query>, element: XHtmlElement<'html>, ) -> ElementId
pub fn set_content( &mut self, element_id: ElementId, inner_html: Option<&'html str>, text_content: Option<Range<usize>>, )
Trait Implementations§
impl<'html, 'query> StructuralPartialEq for Store<'html, 'query>
Auto Trait Implementations§
impl<'html, 'query> Freeze for Store<'html, 'query>
impl<'html, 'query> RefUnwindSafe for Store<'html, 'query>
impl<'html, 'query> Send for Store<'html, 'query>
impl<'html, 'query> Sync for Store<'html, 'query>
impl<'html, 'query> Unpin for Store<'html, 'query>
impl<'html, 'query> UnsafeUnpin for Store<'html, 'query>
impl<'html, 'query> UnwindSafe for Store<'html, 'query>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more