Skip to main content

Store

Struct Store 

Source
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: TextContent

Accumulated text-content buffer shared by all elements.

Implementations§

Source§

impl<'html, 'query: 'html> Store<'html, 'query>

Source

pub fn with_capacity(capacity: usize) -> Self

Source

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());
}
Source

pub fn push( &mut self, from: ElementId, selection: &QuerySection<'query>, element: XHtmlElement<'html>, ) -> ElementId

Source

pub fn set_content( &mut self, element_id: ElementId, inner_html: Option<&'html str>, text_content: Option<Range<usize>>, )

Trait Implementations§

Source§

impl<'html, 'query> Debug for Store<'html, 'query>

Source§

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

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

impl<'html, 'query: 'html> Default for Store<'html, 'query>

Source§

fn default() -> Self

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

impl<'html, 'query> PartialEq for Store<'html, 'query>

Source§

fn eq(&self, other: &Store<'html, 'query>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> 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>,

Source§

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>,

Source§

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.