pub struct Selector { /* private fields */ }
Expand description

Simple query selector

Implementations

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_editor::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]");

Check if the element matches the selector.

use html_editor::{Node, Element, Selector};
use html_editor::prelude::*;
 
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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.