Skip to content

str::split_once is underpowered #76512

Closed
Closed
@HeroicKatora

Description

@HeroicKatora

This nightly feature (#74773) makes it easy to parse key-value pairs or lists.

I could have used this method recently but required the matching character as well. Problematically it would have used a predicate pattern for finding one of several characters. To retrieve it separately is quite awkward with lots of index logic and some unwrap. Should there be a set of alternative method (or this method changed) that returns the separator as well? I'd implement that new set or change the existing methods but wanted to have some feedback on the idea first.

Rough draft of code I wanted to use:

let key_value: &str = _;
if let Some((lhs, sep, rhs)) = key_value.split_once(|ch| ch == '=' || ch == ':') {
    // handle
}

cc: @matklad

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions