Types that can be compared for equality.
Types that implement this protocol can be compared for equality using the ==
and !=
operators.
Many built-in types implement this protocol, such as primitive types, slices, Option, etc.
Equatable
can be automatically generated for by using DefaultEquatable mixin, but if custom equality
comparison is needed, the protocol can be implemented manually.
Method equals must be implemented, other methods can be mixed in.
Example
struct Point { x: i32, y: i32 }
impl Point {
use std::cmp::Equatable;
fn equals(self: &Point, other: &Point) -> bool {
self.x == other.x && self.y == other.y
}
mixin Equatable<Point>;
}
assert_eq!(Point { x: 1, y: 2 }, Point { x: 1, y: 2 });
assert_ne!(Point { x: 1, y: 2 }, Point { x: 1, y: 3 });
Run this example
Required methods
Provided methods
-
Returns
false
if arguments are equal,true
otherwise