From c1ea9e7fcfce001668b74d88632bd2a22066e191 Mon Sep 17 00:00:00 2001 From: James Mills Date: Mon, 25 Apr 2022 19:05:08 +0100 Subject: [PATCH] Add ExactSizeIterator to SubCaptureMatches --- src/re_trait.rs | 11 +++++++++++ src/re_unicode.rs | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/re_trait.rs b/src/re_trait.rs index 680aa5459..7967e2944 100644 --- a/src/re_trait.rs +++ b/src/re_trait.rs @@ -74,8 +74,19 @@ impl<'c> Iterator for SubCapturesPosIter<'c> { self.idx += 1; x } + + fn size_hint(&self) -> (usize, Option) { + 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. diff --git a/src/re_unicode.rs b/src/re_unicode.rs index e4871a621..413fadb14 100644 --- a/src/re_unicode.rs +++ b/src/re_unicode.rs @@ -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) { + 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