// option. This file may not be copied, modified, or distributed
// except according to those terms.
+#![allow(unknown_features)]
+#![feature(box_syntax)]
+
trait Matcher {
fn next_match(&mut self) -> Option<(uint, uint)>;
}
struct CharPredMatcher<'a, 'b> {
str: &'a str,
- pred: |char|:'b -> bool
+ pred: Box<FnMut(char) -> bool + 'b>,
}
impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> {
fn into_matcher(self, &'a str) -> T;
}
-impl<'a, 'b> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for |char|:'b -> bool {
+impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b {
fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
CharPredMatcher {
str: s,
- pred: self
+ pred: box self,
}
}
}
matcher: M
}
-impl<M: Matcher> Iterator<(uint, uint)> for MatchIndices<M> {
+impl<M: Matcher> Iterator for MatchIndices<M> {
+ type Item = (uint, uint);
+
fn next(&mut self) -> Option<(uint, uint)> {
self.matcher.next_match()
}
fn main() {
let s = "abcbdef";
- match_indices(s, |c: char| c == 'b')
+ match_indices(s, |&mut: c: char| c == 'b')
.collect::<Vec<(uint, uint)>>();
}