-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from rust-lang-nursery/optional
Make regex an optional dependency
- Loading branch information
Showing
5 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
extern crate regex; | ||
|
||
use std::fmt; | ||
|
||
use self::regex::Regex; | ||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use std::fmt; | ||
|
||
pub struct Filter { | ||
inner: String, | ||
} | ||
|
||
impl Filter { | ||
pub fn new(spec: &str) -> Result<Filter, String> { | ||
Ok(Filter { inner: spec.to_string() }) | ||
} | ||
|
||
pub fn is_match(&self, s: &str) -> bool { | ||
s.contains(&self.inner) | ||
} | ||
} | ||
|
||
impl fmt::Display for Filter { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
self.inner.fmt(f) | ||
} | ||
} |