Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rnijveld opened this issue Mar 10, 2015 · 2 comments · Fixed by #23269
Closed

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

rnijveld opened this issue Mar 10, 2015 · 2 comments · Fixed by #23269

Comments

@rnijveld
Copy link

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.

@sfackler
Copy link
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.

@shepmaster
Copy link
Member

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

shepmaster added a commit to shepmaster/rust that referenced this issue Mar 20, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Mar 23, 2015
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 a pull request may close this issue.

3 participants