Exerpad
🔥 0
0 XP
Exercise 6 · Chapter: TraitsRequired+50 XP

Fix the Derive

This code tries to print a struct with {:?} and compare two structs with ==, but it's missing the right derive attributes! Add them.

Fix the code so it prints:

Point { x: 1, y: 2 }
Equal: true

Hint: You need #[derive(Debug, PartialEq)] on the struct.

rust
struct Point {
x: i32,
y: i32,
}

fn main() {
let p1 = Point { x: 1, y: 2 };
let p2 = Point { x: 1, y: 2 };
println!("{:?}", p1);
println!("Equal: {}", p1 == p2);
}
Output
Run your code to see the output here.