-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std::slice::ChunkBy
should implement Clone
#137969
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I assume you meant The reason Not sure if this is what you want, but you can try this: pub fn main() {
let slice = &[1, 1, 1, 3, 3, 2, 2, 2];
let mut iter = slice
.chunk_by(|a, b| a == b)
.map(Vec::from)
.collect::<Vec<_>>()
.into_iter();
assert_eq!(iter.next(), Some(vec![1, 1, 1]));
assert_eq!(iter.next(), Some(vec![3, 3]));
let mut iter_clone = iter.clone();
assert_eq!(iter_clone.next(), Some(vec![2, 2, 2]));
assert_eq!(iter_clone.next(), None);
assert_eq!(iter.next(), Some(vec![2, 2, 2]));
assert_eq!(iter.next(), None);
} |
I think that's exactly what they're asking for, which is why |
I believe they actually meant |
Correct; I want Here is a permalink showing an equivalent to what I want, but using |
@nwoods-cimpress: I think you can just add the clone impl in a PR and it will get FCP'd (team consensus voting) by T-libs-api, but if you want to be extra diligent you could 1. find the PR that added the |
PR #138016 submitted. First PR to core Rust; hopefully I got the protocol correct 🤞 |
For context, this was reported on Reddit: https://www.reddit.com/r/rust/comments/1j2sx86/why_is_the_iterator_returned_by_slicechunk_by_not/ |
I tried this code:
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.The text was updated successfully, but these errors were encountered: