1 | extern crate regex; |
2 | |
3 | use std::fmt; |
4 | |
5 | use self::regex::Regex; |
6 | |
7 | #[derive (Debug)] |
8 | pub struct Filter { |
9 | inner: Regex, |
10 | } |
11 | |
12 | impl Filter { |
13 | pub fn new(spec: &str) -> Result<Filter, String> { |
14 | match Regex::new(re:spec) { |
15 | Ok(r: Regex) => Ok(Filter { inner: r }), |
16 | Err(e: Error) => Err(e.to_string()), |
17 | } |
18 | } |
19 | |
20 | pub fn is_match(&self, s: &str) -> bool { |
21 | self.inner.is_match(text:s) |
22 | } |
23 | } |
24 | |
25 | impl fmt::Display for Filter { |
26 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
27 | self.inner.fmt(f) |
28 | } |
29 | } |
30 | |