[go: up one dir, main page]

Trait scraper::selectable::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

Object Safety§

This trait is not object safe.

Implementors§

source§

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

§

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

source§

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

§

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