1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // pretty-expanded FIXME #23616
14 fn next_match(&mut self) -> Option<(usize, usize)>;
17 struct CharPredMatcher<'a, 'b> {
19 pred: Box<FnMut(char) -> bool + 'b>,
22 impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> {
23 fn next_match(&mut self) -> Option<(usize, usize)> {
28 trait IntoMatcher<'a, T> {
29 fn into_matcher(self, &'a str) -> T;
32 impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b {
33 fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
34 // FIXME (#22405): Replace `Box::new` with `box` here when/if possible.
42 struct MatchIndices<M> {
46 impl<M: Matcher> Iterator for MatchIndices<M> {
47 type Item = (usize, usize);
49 fn next(&mut self) -> Option<(usize, usize)> {
50 self.matcher.next_match()
54 fn match_indices<'a, M, T: IntoMatcher<'a, M>>(s: &'a str, from: T) -> MatchIndices<M> {
55 let string_matcher = from.into_matcher(s);
56 MatchIndices { matcher: string_matcher }
61 match_indices(s, |c: char| c == 'b')