Trait Selectable

Source
pub trait Selectable<'a> {
    type Select<'b>: Iterator<Item = ElementRef<'a>>;

    // Required method
    fn select(self, selector: &Selector) -> Self::Select<'_>;
}
Expand description

Trait to abstract over collections of elements to which a CSS selector can be applied

The mainly enables writing helper functions which are generic over Html and ElementRef, e.g.

use scraper::{selectable::Selectable, selector::Selector};

fn text_of_first_match<'a, S>(selectable: S, selector: &Selector) -> Option<String>
where
    S: Selectable<'a>,
{
    selectable.select(selector).next().map(|element| element.text().collect())
}

Required Associated Types§

Source

type Select<'b>: Iterator<Item = ElementRef<'a>>

Iterator over element references matching a [CSS selectorSelector

Required Methods§

Source

fn select(self, selector: &Selector) -> Self::Select<'_>

Applies the given selector to the collection of elements represented by self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> Selectable<'a> for &'a Html

Source§

type Select<'b> = Select<'a, 'b>

Source§

impl<'a> Selectable<'a> for ElementRef<'a>

Source§

type Select<'b> = Select<'a, 'b>