This has confused me before. std::ops::Range<T>
is a struct containing two T
. If it were annotated #[derive(Copy)]
, then for example, Range<usize>
would be Copy
. But for some reason it's not, and so when I store a Range
in a struct that should be able to be Copy
, it can't. I'm curious if there is some reason for this?
Edit: 2025 update, because this is still getting traffic
Rust RFC 3550 proposes fixing this issue by making ranges merely implement IntoIterator
rather than Iterator
, thus allowing them to implement Copy
in a less complicated way. Per its tracking issue, it missed the cutoff for making it into Rust 2024 edition, but could potentially happen in Rust 2027 edition.