str::array_split
for splitting a string into a constant number of substrings
#102905
Labels
A-array
Area: `[T; N]`
A-const-generics
Area: const generics (parameters and arguments)
A-str
Area: str and String
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Related to:
str::split_once
str::splitn
slice::as_chunks
The idea is to provide an API similar to
split_once
, but allowing the programmer to specify any number of substrings at compile time, instead of being limited to two (one split) or relying onsplitn
at runtime.This is helpful for many cases where a programmer wants exactly N substrings, no more and no less, and knows N at compile time.
splitn
can work for this use case, but since you get an iterator out, there's no concise way to get the substrings into an array. You could also have less than N substrings.API
Usage example
Returning an array enables nice features like infallible destructuring:
@rustbot label +T-libs-api +A-str +A-array +A-const-generics
The text was updated successfully, but these errors were encountered: