The https://doc.rust-lang.org/std/slice/struct.ChunksMut.html has the cycle method: https://doc.rust-lang.org/std/iter/struct.Cycle.html#method.cycle that works only when Self: Clone
However, ChunksMut does not implement Clone, therefore I cannot do this:
fn main() {
let a = &[1,2,3,4,5,6];
let mut chunks = a.chunks_mut(2);
let cycle = chunks.cycle();
for c in cycle {
}
}
Why the cycle() method exists if ChunksMut is never Clone?
ChunksMut implements the Iterator trait.
impl<'a, T> Iterator for ChunksMut<'a, T>
And the cycle() comes from the default implementation of Iterator trait. cycle has a predicate(where Self: Clone) which restrict calling cycle on types that are not cloneable.
fn cycle(self) -> Cycle<Self>
where
Self: Clone,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With