Struct Copy / Clone difference

As somebody new to Rust, I am wondering whether there is a subtle difference between clone and copy in the case of a simple struct like

 #[derive(Copy, Clone)]
struct AStruct {
      a: i8,
      b, i8

Copy, clone have the same effect, but are they factually identical in other terms, like performance?

The main difference is the semantics.

std doc Clone in std::clone - Rust and Copy in std::marker - Rust are great materials for your question.


Fab. Got it. Thanks!

You can pass Copy type to more functions.
Copy is built into the language; you can implement your own clone(). You need an obscure reason to make it different though.

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.