Skip to content

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()?

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

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Thank you!

BurntSushi pushed a commit that referenced this pull request Oct 9, 2025
To simplify getting the whole match from `Captures` without needing to
write `unwrap()`.

Fixes #1146, Closes #1227
@BurntSushi BurntSushi closed this in 72618c6 Oct 9, 2025
@tmccombs tmccombs deleted the as-match branch October 10, 2025 06:24
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