Skip to content

Commit

Permalink
fixup! api: Add as_match method
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Sep 20, 2024
1 parent 0fc52dc commit 7311bfc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,16 @@ impl<'h> Captures<'h> {
/// Return the overall match for the capture.
///
/// This returns the match for index `0`. That is it is equivalent to
/// `get(0).unwrap()`
/// `m.get(0).unwrap()`
///
/// ```
/// use regex::bytes::Regex;
///
/// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
/// let caps = re.captures(b" abc123-def").unwrap();
///
/// assert_eq!(caps.as_match().as_bytes(), b"abc123");
/// ```
#[inline]
pub fn as_match(&self) -> Match {
self.get(0).unwrap()
Expand Down
12 changes: 11 additions & 1 deletion src/regex/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,17 @@ impl<'h> Captures<'h> {
/// Return the overall match for the capture.
///
/// This returns the match for index `0`. That is it is equivalent to
/// `get(0).unwrap()`
/// `m.get(0).unwrap()`
///
/// ```
/// use regex::Regex;
///
/// let re = Regex::new(r"[a-z]+([0-9]+)").unwrap();
/// let caps = re.captures(" abc123-def").unwrap();
///
/// assert_eq!(caps.as_match().as_str(), "abc123");
///
/// ```
#[inline]
pub fn as_match(&self) -> Match {
self.get(0).unwrap()
Expand Down

0 comments on commit 7311bfc

Please sign in to comment.