• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
new(spec: &str) -> Result<Filter, String>13     pub fn new(spec: &str) -> Result<Filter, String> {
14         match Regex::new(spec) {
15             Ok(r) => Ok(Filter { inner: r }),
16             Err(e) => Err(e.to_string()),
17         }
18     }
19 
is_match(&self, s: &str) -> bool20     pub fn is_match(&self, s: &str) -> bool {
21         self.inner.is_match(s)
22     }
23 }
24 
25 impl fmt::Display for Filter {
fmt(&self, f: &mut fmt::Formatter) -> fmt::Result26     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27         self.inner.fmt(f)
28     }
29 }
30