Skip to content

std::str::SplitWhitespace does not implement Clone #41655

Closed
@phaylon

Description

@phaylon

It seems currently impossible to iterate over a &str split by whitespace multiple times, due to Clone not being available in any solution.

Given the code

fn takes_iter<'i, I>(_: I) where I: Iterator<Item = &'i str> + Clone {}

fn main() {
    takes_iter("foo bar".split_whitespace());
}

I get the following error

rustc 1.19.0-nightly (afa1240e5 2017-04-29)
error[E0277]: the trait bound `std::str::SplitWhitespace<'_>: std::clone::Clone` is not satisfied
 --> <anon>:4:5
  |
4 |     takes_iter("foo bar".split_whitespace());
  |     ^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `std::str::SplitWhitespace<'_>`
  |
  = note: required by `takes_iter`

error: aborting due to previous error

Other workarounds ("foo bar".split(char::is_whitespace) and "foo bar".split(|c: char| c.is_whitespace()) also run into Clone issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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