The derive macro is a procedural macro that generates automatically an
implementation for selected traits.
In the following example, both Debug and Clone are implemented for User
with generated default implementations:
#[derive(Debug, Clone)]
struct User {
id: u32,
name: String,
}The Clone trait allows us to make an explicit copy of an existing
instance:
let u = User { id: 12, name: String::from("John"), };
let v = u.clone();
println!("id={}, name={}", v.id, v.name);Couldn't automatically determine type of variable `v`.
Please give it an explicit type.And the Debug trait allows to automatically convert an instance into a
string and print it:
v