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
extern crate regex;

use std::fmt;

use self::regex::Regex;

#[derive(Debug)]
pub struct Filter {
    inner: Regex,
}

impl Filter {
    pub fn new(spec: &str) -> Result<Filter, String> {
        match Regex::new(spec) {
            Ok(r) => Ok(Filter { inner: r }),
            Err(e) => Err(e.to_string()),
        }
    }

    pub fn is_match(&self, s: &str) -> bool {
        self.inner.is_match(s)
    }
}

impl fmt::Display for Filter {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        self.inner.fmt(f)
    }
}