Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are iterators not copyable?

Tags:

rust

Many iterators implement the Clone trait, but none of them implement the Copy trait. At least for simple iterators like std:slice::Iter, the Clone implementation looks like a memcpy anyway, so why isn't Copy also implemented?

like image 426
Perseids Avatar asked Sep 01 '15 05:09

Perseids


1 Answers

From PR #20790:

This PR also makes iterator non-implicitly copyable, as this was source of subtle bugs in the libraries. You can still use clone() to explictly copy the iterator.

like image 78
DK. Avatar answered Sep 24 '22 03:09

DK.