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

Add method to get full match from Captures #1146

Open
tmccombs opened this issue Jan 9, 2024 · 3 comments · May be fixed by #1227
Open

Add method to get full match from Captures #1146

tmccombs opened this issue Jan 9, 2024 · 3 comments · May be fixed by #1227

Comments

@tmccombs
Copy link
Contributor

tmccombs commented Jan 9, 2024

Describe your feature request

Add a method to regex::Captures that is equvalent to (or even just this implementation):

#[inline]
fn full_match(&self) -> Match<'h'> {
    self.get(0).unwrap()
}

Getting the full match is a very common operation, and although the documetation for Regex::get says that getting the result at index 0 will always return Some, that property isn't reflected in the type system. And adding a method like this would expose that guarantee through the type of the public API.

@BurntSushi
Copy link
Member

I think this is probably a good idea. I added an analogous method (among others) to the lower level regex-automata::util::captures::Captures type.

I'm not sure full_match is the right name though. Hmmm. I'm not a huge fan of get_match either in this context. Probably match would be ideally, except for the obvious drawback that match is a Rust keyword.

@tmccombs
Copy link
Contributor Author

tmccombs commented Jan 9, 2024

Yeah, I'm not sure full_match is a great name either, but I couldn't think of a better one.

@ultrabear
Copy link

A potential other name could be as_match

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

Successfully merging a pull request may close this issue.

3 participants