Skip to content

Commit

Permalink
api: impl ExactSizeIterator for SubCaptureMatches
Browse files Browse the repository at this point in the history
PR #857
  • Loading branch information
jaehl authored Jul 5, 2022
1 parent 039bb4d commit fb4b1c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/re_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,19 @@ impl<'c> Iterator for SubCapturesPosIter<'c> {
self.idx += 1;
x
}

fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.locs.len() - self.idx;
(len, Some(len))
}

fn count(self) -> usize {
self.len()
}
}

impl<'c> ExactSizeIterator for SubCapturesPosIter<'c> {}

impl<'c> FusedIterator for SubCapturesPosIter<'c> {}

/// `RegularExpression` describes types that can implement regex searching.
Expand Down
10 changes: 10 additions & 0 deletions src/re_unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,8 +1092,18 @@ impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> {
.next()
.map(|cap| cap.map(|(s, e)| Match::new(self.caps.text, s, e)))
}

fn size_hint(&self) -> (usize, Option<usize>) {
self.it.size_hint()
}

fn count(self) -> usize {
self.it.count()
}
}

impl<'c, 't> ExactSizeIterator for SubCaptureMatches<'c, 't> {}

impl<'c, 't> FusedIterator for SubCaptureMatches<'c, 't> {}

/// An iterator that yields all non-overlapping capture groups matching a
Expand Down

0 comments on commit fb4b1c1

Please sign in to comment.