diff options
Diffstat (limited to 'src/libregex')
| -rw-r--r-- | src/libregex/lib.rs | 1 | ||||
| -rw-r--r-- | src/libregex/parse.rs | 10 | ||||
| -rw-r--r-- | src/libregex/re.rs | 7 |
3 files changed, 11 insertions, 7 deletions
diff --git a/src/libregex/lib.rs b/src/libregex/lib.rs index b35c3879783..05f853a851e 100644 --- a/src/libregex/lib.rs +++ b/src/libregex/lib.rs @@ -370,6 +370,7 @@ #![allow(unknown_features)] #![feature(macro_rules, phase, slicing_syntax, globs)] +#![feature(unboxed_closures)] #![deny(missing_docs)] #[cfg(test)] diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index 55e533aadee..ccbd53c4f2a 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -838,8 +838,9 @@ impl<'a> Parser<'a> { // Otherwise, an error will be returned. // Generally, `allow_start` is only true when you're *not* expecting an // opening parenthesis. - fn pos_last(&self, allow_start: bool, pred: |&BuildAst| -> bool) - -> Result<uint, Error> { + fn pos_last<P>(&self, allow_start: bool, pred: P) -> Result<uint, Error> where + P: FnMut(&BuildAst) -> bool, + { let from = match self.stack.iter().rev().position(pred) { Some(i) => i, None => { @@ -887,8 +888,9 @@ impl<'a> Parser<'a> { // build_from combines all AST elements starting at 'from' in the // parser's stack using 'mk' to combine them. If any such element is not an // AST then it is popped off the stack and ignored. - fn build_from(&mut self, from: uint, mk: |Ast, Ast| -> Ast) - -> Result<Ast, Error> { + fn build_from<F>(&mut self, from: uint, mut mk: F) -> Result<Ast, Error> where + F: FnMut(Ast, Ast) -> Ast, + { if from >= self.stack.len() { return self.err("Empty group or alternate not allowed.") } diff --git a/src/libregex/re.rs b/src/libregex/re.rs index 2a1fda06431..1504e191985 100644 --- a/src/libregex/re.rs +++ b/src/libregex/re.rs @@ -429,10 +429,11 @@ impl Regex { /// /// ```rust /// # #![feature(phase)] + /// # #![feature(unboxed_closures)] /// # extern crate regex; #[phase(plugin)] extern crate regex_macros; /// # use regex::Captures; fn main() { /// let re = regex!(r"([^,\s]+),\s+(\S+)"); - /// let result = re.replace("Springsteen, Bruce", |caps: &Captures| { + /// let result = re.replace("Springsteen, Bruce", |&: caps: &Captures| { /// format!("{} {}", caps.at(2), caps.at(1)) /// }); /// assert_eq!(result.as_slice(), "Bruce Springsteen"); @@ -585,7 +586,7 @@ impl<'t> Replacer for &'t str { } } -impl<'t> Replacer for |&Captures|: 't -> String { +impl<F> Replacer for F where F: FnMut(&Captures) -> String { fn reg_replace<'a>(&'a mut self, caps: &Captures) -> CowString<'a> { (*self)(caps).into_cow() } @@ -767,7 +768,7 @@ impl<'t> Captures<'t> { // How evil can you get? // FIXME: Don't use regexes for this. It's completely unnecessary. let re = Regex::new(r"(^|[^$]|\b)\$(\w+)").unwrap(); - let text = re.replace_all(text, |refs: &Captures| -> String { + let text = re.replace_all(text, |&mut: refs: &Captures| -> String { let (pre, name) = (refs.at(1), refs.at(2)); format!("{}{}", pre, match from_str::<uint>(name.as_slice()) { |
