Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: Add as_match method #1227

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/regex/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,15 @@ impl<'h> Captures<'h> {
.map(|sp| Match::new(self.haystack, sp.start, sp.end))
}

/// Return the overall match for the capture.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an example. I try to include an example for every public API item.

///
/// This returns the match for index `0`. That is it is equivalent to
/// `get(0).unwrap()`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use m.get(0).unwrap()?

#[inline]
pub fn as_match(&self) -> Match {
self.get(0).unwrap()
}

/// Returns the `Match` associated with the capture group named `name`. If
/// `name` isn't a valid capture group or it refers to a group that didn't
/// match, then `None` is returned.
Expand Down
9 changes: 9 additions & 0 deletions src/regex/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,15 @@ impl<'h> Captures<'h> {
.map(|sp| Match::new(self.haystack, sp.start, sp.end))
}

/// Return the overall match for the capture.
///
/// This returns the match for index `0`. That is it is equivalent to
/// `get(0).unwrap()`
#[inline]
pub fn as_match(&self) -> Match {
self.get(0).unwrap()
}

/// Returns the `Match` associated with the capture group named `name`. If
/// `name` isn't a valid capture group or it refers to a group that didn't
/// match, then `None` is returned.
Expand Down