Skip to content

regex: add Regex::split_once method#1343

Open
RavuAlHemio wants to merge 1 commit intorust-lang:masterfrom
RavuAlHemio:split_once
Open

regex: add Regex::split_once method#1343
RavuAlHemio wants to merge 1 commit intorust-lang:masterfrom
RavuAlHemio:split_once

Conversation

@RavuAlHemio
Copy link
Copy Markdown

Convenience function that works like str::split_once in the standard library.

Motivation:

The most common syntax for the HTTP WWW-Authenticate header is:

WWW-Authenticate: <auth-scheme> <auth-param>, …, <auth-paramN>

where the tokens are separated by one or more instances of whitespace. split_once would allow quick splitting off <auth-scheme> from the <auth-param>s without the iteration and possible allocation behavior of full-fledged split/splitn.

Bonus for having this in regex itself: getting the lifetime annotations right, especially in the return value, can be rather daunting for programmers new to Rust and trying their hand at an ad-hoc implementation -- I remember lots of trial and error before the whole thing clicked for me.

Convenience function that works like `str::split_once` in the standard
library.
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.

1 participant