1extern crate regex;
2
3use std::fmt;
4
5use self::regex::Regex;
6
7#[derive(Debug)]
8pub struct Filter {
9 inner: Regex,
10}
11
12impl 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(haystack:s)
22 }
23}
24
25impl fmt::Display for Filter {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 self.inner.fmt(f)
28 }
29}
30