Skip to content

Commit fb4b1c1

Browse files
authored
api: impl ExactSizeIterator for SubCaptureMatches
PR #857
1 parent 039bb4d commit fb4b1c1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/re_trait.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,19 @@ impl<'c> Iterator for SubCapturesPosIter<'c> {
7474
self.idx += 1;
7575
x
7676
}
77+
78+
fn size_hint(&self) -> (usize, Option<usize>) {
79+
let len = self.locs.len() - self.idx;
80+
(len, Some(len))
81+
}
82+
83+
fn count(self) -> usize {
84+
self.len()
85+
}
7786
}
7887

88+
impl<'c> ExactSizeIterator for SubCapturesPosIter<'c> {}
89+
7990
impl<'c> FusedIterator for SubCapturesPosIter<'c> {}
8091

8192
/// `RegularExpression` describes types that can implement regex searching.

src/re_unicode.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,8 +1092,18 @@ impl<'c, 't> Iterator for SubCaptureMatches<'c, 't> {
10921092
.next()
10931093
.map(|cap| cap.map(|(s, e)| Match::new(self.caps.text, s, e)))
10941094
}
1095+
1096+
fn size_hint(&self) -> (usize, Option<usize>) {
1097+
self.it.size_hint()
1098+
}
1099+
1100+
fn count(self) -> usize {
1101+
self.it.count()
1102+
}
10951103
}
10961104

1105+
impl<'c, 't> ExactSizeIterator for SubCaptureMatches<'c, 't> {}
1106+
10971107
impl<'c, 't> FusedIterator for SubCaptureMatches<'c, 't> {}
10981108

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

0 commit comments

Comments
 (0)