Skip to content

std::slice::ChunkBy should implement Clone #137969

@nwoods-cimpress

Description

@nwoods-cimpress

I tried this code:

pub fn main() {
    let slice = &[1, 1, 1, 3, 3, 2, 2, 2];
    let mut iter = slice.chunk_by(|a, b| a == b);
    assert_eq!(iter.next(), Some(&[1, 1, 1][..]));
    assert_eq!(iter.next(), Some(&[3, 3][..]));

    let mut iter_clone = iter.clone();
    assert_eq!(iter_clone.next(), Some(&[2, 2, 2][..]));
    assert_eq!(iter_clone.next(), None);

    assert_eq!(iter.next(), Some(&[2, 2, 2][..]));
    assert_eq!(iter.next(), None);
}

I expected to see this happen: Code compiles and runs

Instead, this happened: Compilation error by virtue of std::slice::ChunkBy not implementing Clone

If there is a reason that Clone cannot be supported, I don't understand it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-iteratorsArea: IteratorsC-bugCategory: This is a bug.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