Eq
trait Eq<T>
Source: compiler/src/builtin_docs/prelude/ops.hy The equality operators == and !=.
a == b calls eq(a, b) and a != b calls ne(a, b) on a type with an
Eq instance. The primitives have builtin instances (strings compare by
content). Arrays, Vecs, tuples, records and enums compare structurally,
and an element with an Eq instance (a class’s too) compares with it.
Classes without an instance compare by identity. #[derive(Eq)]
generates a field-by-field instance.
Required methods#
Examples#
use tests::assert;
class Money {
pub cents: int,
}
impl Eq for Money {
pub fn eq(Money a, Money b) -> bool {
return a.cents == b.cents;
}
pub fn ne(Money a, Money b) -> bool {
return a.cents != b.cents;
}
}
fn main() {
assert!(new Money(100) == new Money(100));
assert!(new Money(1) != new Money(2));
}