Skip to content

Commit 526fd07

Browse files
committed
Merge pull request #70 from blaenk/from_str
implement FromStr for Regex
2 parents 910aef4 + e010a8b commit 526fd07

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/re.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::collections::hash_map::Iter;
1414
use std::fmt;
1515
#[cfg(feature = "pattern")]
1616
use std::str::pattern::{Pattern, Searcher, SearchStep};
17+
use std::str::FromStr;
1718

1819
use compile::Program;
1920
use parse;
@@ -158,6 +159,15 @@ impl fmt::Debug for Regex {
158159
}
159160
}
160161

162+
impl FromStr for Regex {
163+
type Err = parse::Error;
164+
165+
/// Attempts to parse a string into a regular expression
166+
fn from_str(s: &str) -> Result<Regex, parse::Error> {
167+
Regex::new(s)
168+
}
169+
}
170+
161171
impl Regex {
162172
/// Compiles a dynamic regular expression. Once compiled, it can be
163173
/// used repeatedly to search, split or replace text in a string.

0 commit comments

Comments
 (0)