pub struct CompiledSelector { /* private fields */ }Expand description
A pre-compiled CSS selector for reuse across documents and threads.
Parsing a CSS selector string has non-trivial cost. When the same selector is used to query many documents (e.g., in a scraping loop), compile it once and reuse it to eliminate repeated parse overhead.
§Example
use fhp_tree::parse;
use fhp_selector::{CompiledSelector, Selectable};
let sel = CompiledSelector::new("div.content").unwrap();
let doc = parse("<div class=\"content\">Hello</div>").unwrap();
let results = doc.select_compiled(&sel).unwrap();
assert_eq!(results.len(), 1);Implementations§
Source§impl CompiledSelector
impl CompiledSelector
Sourcepub fn new(css: &str) -> Result<Self, SelectorError>
pub fn new(css: &str) -> Result<Self, SelectorError>
Compile a CSS selector string.
§Errors
Returns SelectorError::Invalid if the selector syntax is invalid.
Sourcepub fn as_list(&self) -> &SelectorList
pub fn as_list(&self) -> &SelectorList
Access the underlying parsed selector list.
Trait Implementations§
Source§impl Clone for CompiledSelector
impl Clone for CompiledSelector
Source§fn clone(&self) -> CompiledSelector
fn clone(&self) -> CompiledSelector
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CompiledSelector
impl RefUnwindSafe for CompiledSelector
impl Send for CompiledSelector
impl Sync for CompiledSelector
impl Unpin for CompiledSelector
impl UnsafeUnpin for CompiledSelector
impl UnwindSafe for CompiledSelector
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