Closed KarelPeeters closed 2 years ago
The disadvantage I had in mind is that it prevents accidentally using the same move twice.
I tried the same with Piece
, so that putting a piece on the board consumes it, but that was just too annoying to work with. I didn't find the same for Move
. Will you really need a lot of cloning?
Pushed a copy-move
branch to experiment.
Yeah I guess that's true, and not deriving Copy
for types where it's actually dangerous if they are used twice makes sense. But intuitively a chess move is not some "heavy" object, it's just a small atomic thing. I was surprised when I started using this crate so that's why I made this issue.
The Copy
docs say this:
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.
(My specific use case is that I'm trying to replace the chess backend chess crate used in https://github.com/KarelPeeters/board-game-rs with shakmatey because the chess crate takes a long time to compile, and there I started out by assuming that moves are Copy. I might change this back to not requiring copy later on for more complex games, so it's not super important for me.)
Keeping !Copy
for now.
The
Move
enum has a simple definition, and is very small: when I compile the crate it's only 8 bytes/64 bits. It would be very convenient if it derived theCopy
trait so we don't need to call.clone
or work with references anywhere. I can't really think of any disadvantages.