std::equatable
Import with import std::equatable.
Exports
Section titled “Exports”Interfaces
interface Equatable
Section titled “interface Equatable”interface Equatable fn equal(a: self, b: self) -> Bool end
Protocol for equality between two values of the same type.
Equatable.equal(a, b) returns True when a and b are equal under
the implementor’s notion of equality. == calls it, and != is its
negation.
A struct, enum or distinct type with no impl of its own compares
structurally: field by field, or variant and then payload. A
hand-written impl Equatable replaces that comparison for its type
wherever a value of it sits, so [a] == [b], Some(a) == Some(b) and a
Map lookup by key all agree with a == b.
The primitive types Int, Float, Bool and String compare
directly, and so does Unit, whose one value equals itself. To
implement it for a custom type:
pub struct Point x: Int y: Int end impl Equatable for Point fn equal(a: Point, b: Point) -> Bool a.x == b.x and a.y == b.y end end
derive Equatable synthesizes pairwise field equality for structs,
variant-then-payload comparison for enums, and inner-value delegation for
distinct types.
Equatable.equal
Section titled “Equatable.equal”fn equal(a: self, b: self) -> Bool
interface Equatable