trait

PartialEq — equality comparison

PartialEq defines equality checks, including == and !=. Derive it for field-wise comparison when that matches the domain. For a type compared to itself the intended relation can be non-reflexive, as with NaN. Expected stdout (not executed): true Common mistake: Assuming PartialEq guarantees that every value equals itself.

Formal Syntax & Structure

rust syntaxrust
fn eq(&self, other: &Rhs) -> bool

Working Example

Example Snippetrust
#[derive(PartialEq)]struct Ticket { id: u32 }fn main() {    let a = Ticket { id: 8 };    let b = Ticket { id: 8 };    println!("{}", a == b);}
Rust Reference