pub struct Selector { /* private fields */ }
Expand description
Simple query selector
Implementations§
Source§impl Selector
impl Selector
Sourcepub fn from(selector: &str) -> Self
pub fn from(selector: &str) -> Self
The selector
only supports type selector, ID selector and class selector.
For example, div#app
, span
would be ok, but .container > div
,
#app *
would get unexpected results.
use html_query_parser::Selector;
// Ok: Simple tag, class and ID selectors.
let selector = Selector::from("span");
let selector = Selector::from(".class");
let selector = Selector::from("#id");
// Ok: Mixed selector
let selector = Selector::from("div#app");
let selector = Selector::from("span.info#first");
// Disallowed
let selector = Selector::from("div span");
let selector = Selector::from("a[target=_blank]");
Sourcepub fn matches(&self, element: &Element) -> bool
pub fn matches(&self, element: &Element) -> bool
Check if the element
matches the selector
.
use html_query_parser::{Node, Element, Selector, Htmlifiable};
let element: Element = Element::new(
"div",
vec![("id", "app")],
vec![Node::Text("Hello World!".to_string())],
);
let selector = Selector::from("div#app");
assert_eq!(selector.matches(&element), true);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Selector
impl RefUnwindSafe for Selector
impl Send for Selector
impl Sync for Selector
impl Unpin for Selector
impl UnwindSafe for Selector
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