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

Conversation

tmccombs
Copy link
Contributor

@tmccombs tmccombs commented Sep 19, 2024

To simplify getting the whole match from Captures

Fixes #1146

To simplify getting the whole match from Captures
/// Return the overall match for the capture.
///
/// 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()?

@@ -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.

/// let caps = re.captures(b" abc123-def").unwrap();
///
/// assert_eq!(caps.as_match().as_bytes(), b"abc123");
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

This example is not formatted in the same way as all other examples.

Please look at other public API items and format this one in the same way. It should have an # Example heading, for example.

@BurntSushi
Copy link
Member

Also, I think the name as_match is not ideal. I used get_match in the lower level API. get_match isn't ideal either, but I think it's probably better than as_match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method to get full match from Captures
2 participants