Skip to content

StrExt::splitn requires a DoubleEndedSearcher whereas StrExt::split does not #23262

Closed
@rnijveld

Description

@rnijveld

Wanting to limit your splits to a certain number suddenly requires the pattern to implement DoubleEndedSearcher, so the following code fragment using strings as splits fails:

fn main() {
   let v1: Vec<_> = "test::thing::test".split("::").collect();
   let v2: Vec<_> = "test::thing::test".splitn(1, "::").collect();
}

With:

<anon>:3:54: 3:63 error: type `core::str::SplitN<'_, &str>` does not implement any method in scope named `collect`
<anon>:3    let v2: Vec<_> = "test:thing:test".splitn(1, ":").collect();
                                                              ^~~~~~~~~

I would expect both of them to have pretty much the same requirements as for the pattern argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions