QueryBuilderExt

Trait QueryBuilderExt 

Source
pub trait QueryBuilderExt {
    // Required method
    fn get_handle(&self) -> Handle;

    // Provided methods
    fn limit<'a>(&self, limit: usize) -> QueryBuilder<'a, (), ()> { ... }
    fn tag<'a, P: Pattern>(
        &self,
        tag: P,
    ) -> QueryBuilder<'a, TagQuery<P>, QueryWrapper<'a, (), ()>> { ... }
    fn attr_name<'a, P>(
        &self,
        name: P,
    ) -> QueryBuilder<'a, AttrQuery<P, bool>, QueryWrapper<'a, (), ()>>
       where P: Pattern { ... }
    fn attr_value<'a, P>(
        &self,
        value: P,
    ) -> QueryBuilder<'a, AttrQuery<bool, P>, QueryWrapper<'a, (), ()>>
       where P: Pattern { ... }
    fn attr<'a, P, Q>(
        &self,
        name: P,
        value: Q,
    ) -> QueryBuilder<'a, AttrQuery<P, Q>, QueryWrapper<'a, (), ()>>
       where P: Pattern,
             Q: Pattern { ... }
    fn class<'a, P: Pattern>(
        &self,
        value: P,
    ) -> QueryBuilder<'a, AttrQuery<&'static str, P>, QueryWrapper<'a, (), ()>> { ... }
    fn recursive<'a>(&self, recursive: bool) -> QueryBuilder<'a, (), ()> { ... }
    fn children(&self) -> NodeChildIter { ... }
    fn parents(&self) -> NodeParentIter { ... }
}
Expand description

Adds the QueryBuilder constructor methods to the implementing type

Required Methods§

Source

fn get_handle(&self) -> Handle

Retrieves the Handle that these methods will work on

Provided Methods§

Source

fn limit<'a>(&self, limit: usize) -> QueryBuilder<'a, (), ()>

Starts building a Query, with limit limit

Source

fn tag<'a, P: Pattern>( &self, tag: P, ) -> QueryBuilder<'a, TagQuery<P>, QueryWrapper<'a, (), ()>>

Starts building a Query, with tag tag

Source

fn attr_name<'a, P>( &self, name: P, ) -> QueryBuilder<'a, AttrQuery<P, bool>, QueryWrapper<'a, (), ()>>
where P: Pattern,

Starts building a Query, with attr name name

Source

fn attr_value<'a, P>( &self, value: P, ) -> QueryBuilder<'a, AttrQuery<bool, P>, QueryWrapper<'a, (), ()>>
where P: Pattern,

Starts building a Query, with attr value value

Source

fn attr<'a, P, Q>( &self, name: P, value: Q, ) -> QueryBuilder<'a, AttrQuery<P, Q>, QueryWrapper<'a, (), ()>>
where P: Pattern, Q: Pattern,

Starts building a Query, with attr attr

Source

fn class<'a, P: Pattern>( &self, value: P, ) -> QueryBuilder<'a, AttrQuery<&'static str, P>, QueryWrapper<'a, (), ()>>

Starts building a Query, with class class

Source

fn recursive<'a>(&self, recursive: bool) -> QueryBuilder<'a, (), ()>

Starts building a Query, with recursion set to recursive

Source

fn children(&self) -> NodeChildIter

Returns an iterator over the node’s children

§Example
use soup::prelude::*;

let soup = Soup::new(r#"<ul><li>ONE</li><li>TWO</li><li>THREE</li></ul>"#);
let ul = soup.tag("ul").find().expect("couldn't find 'ul'");
let li_text = ul.children()
                .filter(|node| node.is_element())
                .map(|node| node.text().to_string())
                .collect::<Vec<_>>();
assert_eq!(li_text, vec!["ONE".to_string(), "TWO".to_string(), "THREE".to_string()]);
Source

fn parents(&self) -> NodeParentIter

Iterator over the parents of a node

§Example
use soup::prelude::*;

let soup = Soup::new(r#"<div><p><b>FOO</b></p></div>"#);
let b = soup.tag("b").find().expect("Couldn't find tag 'b'");
let parents = b.parents().map(|node| node.name().to_string()).collect::<Vec<_>>();
assert_eq!(parents, vec!["p".to_string(), "div".to_string(), "body".to_string(), "html".to_string(), "[document]".to_string()]);

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.

Implementations on Foreign Types§

Source§

impl QueryBuilderExt for Handle

Implementors§