I think I have understood it a little bit. I am not well versed with the where syntax, so I tried the below snippets:
struct Person<T> {
age: u32,
gender: T
}
impl<T> Copy for Person<T> {}
#[derive(Copy, Clone)]
struct Person<T> {
age: u32,
gender: T
}
In the first snippet, the compiler complains that "the trait Copy may not be implemented for type(Gender)".
The second snippet doesn't raise any errors. So, does that mean using the derive approach implicitly applies Copy trait to the fields of a struct.
No, it restricts the implementation based on the named trait parameters. As most trait parameters represent field types, this is usually what you want. Sometimes, however, the field that uses the trait parameter implements Copy even when the parameter doesn't. For example, this is only Copy if T:Copy:
But that's not strictly necessary, as references always implement Copy. If you have a MyRef<Mutex<...>>, for example, you wouldn't be able to copy or clone it. In this case, you'd probably want to write: