Pattern

Trait Pattern 

Source
pub trait Pattern {
    // Required method
    fn matches(&self, haystack: &str) -> bool;
}
Expand description

A trait used to indicate a type which can be used to match a value

Any type that implements this trait can be passed to the various QueryBuilder methods in order to match an element

§Example

use soup::{pattern::Pattern, prelude::*};

struct MyType(String);

impl Pattern for MyType {
    fn matches(&self, haystack: &str) -> bool {
        self.0.matches(haystack)
    }
}

let soup = Soup::new(r#"<div id="foo"></div>"#);
let result = soup.tag(MyType("div".to_string())).find().expect("Couldn't find div with id foo");
assert_eq!(result.get("id").expect("Couldn't get attribute 'id'"), "foo".to_string());

Required Methods§

Source

fn matches(&self, haystack: &str) -> bool

Matches the Pattern with the value haystack

Implementations on Foreign Types§

Source§

impl Pattern for bool

Source§

fn matches(&self, _haystack: &str) -> bool

Source§

impl Pattern for String

Source§

fn matches(&self, haystack: &str) -> bool

Source§

impl Pattern for Regex

Source§

fn matches(&self, haystack: &str) -> bool

Source§

impl<'a> Pattern for &'a str

Source§

fn matches(&self, haystack: &str) -> bool

Implementors§