Description
According to the documentation of core::marker::Copy
,
Generally speaking, if your type can implement
Copy
, it should. Keep in mind, though, that implementingCopy
is part of the public API of your type. If the type might become non-Copy
in the future, it could be prudent to omit theCopy
implementation now, to avoid a breaking API change.
Zero-sized types in general are a bit tricky in that regard because they (just like core::marker::PhantomData
) can be used to represent ownership over values of types that non-trivially implement core::ops::Drop
.
However, zero-length arrays perhaps should implement Copy
because they can be bit-wise copied (assuming 0-bit/0-byte copy is permitted). It would allow implementing Copy
on overaligned types like the one below:
Is there anything that stops implementing Copy
on zero-length arrays aside from marker trait attribute dependency?
P.S. I would love to have a generic type where the first generic parameter would be the type of the stored value and the second parameter would be a generic constant of type usize
whose value would be used as a constraint for alignment, yet it is a story for discussion on Rust internals/another issue/RFC.
Activity