Trait soup::pattern::Pattern[][src]

pub trait Pattern {
    fn matches(&self, haystack: &str) -> bool;
}

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

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

Matches the Pattern with the value haystack

Loading content...

Implementations on Foreign Types

impl Pattern for bool[src]

impl<'a> Pattern for &'a str[src]

impl Pattern for String[src]

impl Pattern for Regex[src]

Loading content...

Implementors

Loading content...