ModularM
Modular2y ago
12 replies
bunny

Trait `Comparable`

I looked around, but do not see an answer so far. Does Mojo have a Trait like Comparable to indicate that a Struct has implemented all of the comparison dunder methods? Something like:
trait Comparable:
    # == equal
    fn __eq__(self, other: Self) -> Bool: ...
    # != not equal
    fn __ne__(self, other: Self) -> Bool: ...
    # > greater than
    fn __gt__(self, other: Self) -> Bool: ...
    # < less than
    fn __lt__(self, other: Self) -> Bool: ...
    # >= greater than or equal
    fn __ge__(self, other: Self) -> Bool: ...
    # <= less than or equal
    fn __le__(self, other: Self) -> Bool: ...
Was this page helpful?