Trait for comparisons using the equality operator. Implementing this trait for types provides the == and != operators for those types. This trait can be used with #[derive]. When derived on structs, two instances are equal if all fields are equal, and not equal if any fields are not equal. When derived on enums, two instances are equal if they are the same variant and all fields are equal.

Signature

pub trait PartialEq

Examples

An example in which two points are equal if their x and y coordinates are equal.
#[derive(Copy, Drop)]
struct Point {
    x: u32,
    y: u32
}

impl PointEq of PartialEq {
    fn eq(lhs: @Point, rhs: @Point) -> bool {
        lhs.x == rhs.x && lhs.y == rhs.y
    }
}

let p1 = Point { x: 1, y: 2 };
let p2 = Point { x: 1, y: 2 };
assert!(p1 == p2);
assert!(!(p1 != p2));

Trait functions

eq

Returns whether lhs and rhs equal, and is used by ==.

Signature

fn eq(lhs: @T, rhs: @T) -> bool

Examples

assert!(1 == 1);

ne

Returns whether lhs and rhs are not equal, and is used by !=.

Signature

fn ne(lhs: @T, rhs: @T) -> bool

Examples

assert!(0 != 1);