Why is `Copy` not implemented for `std::io::Cursor`?

The title says most of it, but is there a specific reason why there is no impl<T: Copy> Copy for Cursor<T>? Taking Cursor<&[u8]> as an example, it semantically makes total sense to cheaply copy this type around, e.g. if i have functions that read from the cursor's position but the caller still wants to continue from that position.

The best reason I can think of as to why Copy shouldn't be implemented on the type is for expanding the type with some non-Copy fields further down the road, but then the idea of a "Cursor" doesn't feel like it should be too heavy anyway.

Aside from future compatibility, I think the main argument against it is the same as against having Copy iterators: it's too easy to accidentally operate on a copy and then lose the change of state.

1 Like

And note that you can clone() a Cursor, and if the contents are Copy then this is no more expensive than a copy would be.

5 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.