Derive PartialEq and Eq traits on your struct to enable equality comparisons using == and != operators.
Add the PartialEq and Eq traits to your struct using the #[derive] attribute to enable equality comparisons with == and !=.
#[derive(PartialEq, Eq)]
struct Point {
x: i32,
y: i32,
}
fn main() {
let a = Point { x: 1, y: 2 };
let b = Point { x: 1, y: 2 };
assert_eq!(a, b);
}
These traits tell Rust how to check if two items are the same. PartialEq allows basic equality checks, while Eq guarantees that an item is always equal to itself, which is required for using your struct as a key in a hash map. Think of it like teaching the computer how to compare two identical keys to see if they open the same lock.