Skip to content

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

Closed

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.

Activity

  1. sfackler commented on Mar 10, 2015

    @sfackler
    Member

    At the very least, the trait bound should be placed on splitn as well so you get a compilation error in the right place.

  2. shepmaster commented on Mar 14, 2015

    @shepmaster
    Member

    @sfackler some conversation on the PR indicates that we aren't going to add the trait bounds on the method.

  3. added a commit that references this issue on Mar 23, 2015
    67e516c
  4. added a commit that references this issue on Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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