Struct lol_html::Selector

source ·
pub struct Selector(/* private fields */);
Expand description

Parsed CSS selector.

Parsed selector can be used for different element content handlers without a necessity to re-parse CSS selector string for each of them.

§Example

The structure implements the FromStr trait, so it can be constructed through str’s parse method.

use lol_html::Selector;

let selector: Selector = "#foo".parse().unwrap();

§Supported selector

Currently the rewriter supports the following CSS selectors:

PatternRepresents
*any element
Eany element of type E
E:nth-child(n)an E element, the n-th child of its parent
E:first-childan E element, first child of its parent
E:nth-of-type(n)an E element, the n-th sibling of its type
E:first-of-typean E element, first sibling of its type
E:not(s)an E element that does not match either compound selector s
E.warningan E element belonging to the class warning
E#myidan E element with ID equal to "myid".
E[foo]an E element with a foo attribute
E[foo="bar"]an E element whose foo attribute value is exactly equal to "bar"
E[foo="bar" i]an E element whose foo attribute value is exactly equal to any (ASCII-range) case-permutation of "bar"
E[foo="bar" s]an E element whose foo attribute value is exactly and case-sensitively equal to "bar"
E[foo~="bar"]an E element whose foo attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar"
E[foo^="bar"]an E element whose foo attribute value begins exactly with the string "bar"
E[foo$="bar"]an E element whose foo attribute value ends exactly with the string "bar"
E[foo*="bar"]an E element whose foo attribute value contains the substring "bar"
E[foo|=“en”]an E element whose foo attribute value is a hyphen-separated list of values beginning with "en"
E Fan F element descendant of an E element
E > Fan F element child of an E element

Trait Implementations§

source§

impl Clone for Selector

source§

fn clone(&self) -> Selector

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Selector

source§

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

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

impl FromStr for Selector

§

type Err = SelectorError

The associated error which can be returned from parsing.
source§

fn from_str(selector: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.