Skip to content

Commit 12c0edb

Browse files
committed
Update search.rs
1 parent c140536 commit 12c0edb

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

regex-automata/src/util/search.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,16 +1365,17 @@ impl<'a> Iterator for PatternSetIter<'a> {
13651365
type Item = PatternID;
13661366

13671367
fn next(&mut self) -> Option<PatternID> {
1368-
while let Some((index, &yes)) = self.it.next() {
1368+
// Only valid 'PatternID' values can be inserted into the set
1369+
// and construction of the set panics if the capacity would
1370+
// permit storing invalid pattern IDs. Thus, 'yes' is only true
1371+
// precisely when 'index' corresponds to a valid 'PatternID'.
1372+
self.it.by_ref().find_map(|(index, &yes)| {
13691373
if yes {
1370-
// Only valid 'PatternID' values can be inserted into the set
1371-
// and construction of the set panics if the capacity would
1372-
// permit storing invalid pattern IDs. Thus, 'yes' is only true
1373-
// precisely when 'index' corresponds to a valid 'PatternID'.
1374-
return Some(PatternID::new_unchecked(index));
1374+
Some(PatternID::new_unchecked(index))
1375+
} else {
1376+
None
13751377
}
1376-
}
1377-
None
1378+
})
13781379
}
13791380

13801381
fn size_hint(&self) -> (usize, Option<usize>) {
@@ -1689,13 +1690,14 @@ impl Anchored {
16891690
/// # Ok::<(), Box<dyn std::error::Error>>(())
16901691
/// ```
16911692
#[non_exhaustive]
1692-
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
1693+
#[derive(Clone, Copy, Default, Debug, Eq, PartialEq)]
16931694
pub enum MatchKind {
16941695
/// Report all possible matches.
16951696
All,
16961697
/// Report only the leftmost matches. When multiple leftmost matches exist,
16971698
/// report the match corresponding to the part of the regex that appears
16981699
/// first in the syntax.
1700+
#[default]
16991701
LeftmostFirst,
17001702
// There is prior art in RE2 that shows that we should be able to add
17011703
// LeftmostLongest too. The tricky part of it is supporting ungreedy
@@ -1721,12 +1723,6 @@ impl MatchKind {
17211723
}
17221724
}
17231725

1724-
impl Default for MatchKind {
1725-
fn default() -> MatchKind {
1726-
MatchKind::LeftmostFirst
1727-
}
1728-
}
1729-
17301726
/// An error indicating that a search stopped before reporting whether a
17311727
/// match exists or not.
17321728
///

0 commit comments

Comments
 (0)