Skip to content

Commit 0fc52dc

Browse files
committed
api: Add as_match method
To simplify getting the whole match from Captures
1 parent ab88aa5 commit 0fc52dc

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/regex/bytes.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,15 @@ impl<'h> Captures<'h> {
16651665
.map(|sp| Match::new(self.haystack, sp.start, sp.end))
16661666
}
16671667

1668+
/// Return the overall match for the capture.
1669+
///
1670+
/// This returns the match for index `0`. That is it is equivalent to
1671+
/// `get(0).unwrap()`
1672+
#[inline]
1673+
pub fn as_match(&self) -> Match {
1674+
self.get(0).unwrap()
1675+
}
1676+
16681677
/// Returns the `Match` associated with the capture group named `name`. If
16691678
/// `name` isn't a valid capture group or it refers to a group that didn't
16701679
/// match, then `None` is returned.

src/regex/string.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,15 @@ impl<'h> Captures<'h> {
16751675
.map(|sp| Match::new(self.haystack, sp.start, sp.end))
16761676
}
16771677

1678+
/// Return the overall match for the capture.
1679+
///
1680+
/// This returns the match for index `0`. That is it is equivalent to
1681+
/// `get(0).unwrap()`
1682+
#[inline]
1683+
pub fn as_match(&self) -> Match {
1684+
self.get(0).unwrap()
1685+
}
1686+
16781687
/// Returns the `Match` associated with the capture group named `name`. If
16791688
/// `name` isn't a valid capture group or it refers to a group that didn't
16801689
/// match, then `None` is returned.

0 commit comments

Comments
 (0)