1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Traits & impls for matching types with strings
use Regex;
/// 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
///
/// ```rust
/// # extern crate soup;
/// 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());
/// ```