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 }
Protocol for structural equality between two values of the same type.
Equatable.equal?(a, b) returns True iff a and b are equal under
the implementor’s notion of equality. The == operator desugars to
Equatable.equal?(...) for any type that impl this interface;
!= desugars to its negation.
All four primitive types — Int, Float, Bool, String —
implement Equatable using the underlying primitive equality. To
implement it for a custom type:
pub struct Point { x: Int y: Int } impl Equatable for Point { fn equal?(a: Point, b: Point): Bool { a.x == b.x and a.y == b.y } }
derive Equatable synthesizes pairwise field equality for structs,
variant-then-payload comparison for enums, and inner-value delegation for
distinct types.