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());