derive Attributes
#[derive(...)] adds Debug, Clone, PartialEq and more automatically.
Example
#[derive(Debug, Clone, PartialEq)]
struct P { x: i32, y: i32 }
fn main() {
let a = P { x: 1, y: 2 };
let b = a.clone();
println!("{:?} {}", a, a == b);
}Result
P { x: 1, y: 2 } trueExercise
Debug derive.
#[derive()]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.