cpp_utils/cmp.rs
1//! Comparison operator traits
2//!
3//! C++'s comparison operators have different semantics from Rust's `PartialOrd` and `Ord` traits.
4//! If all the operators (`Lt`, `Le`, `Gt`, `Ge`) are implemented for a type, the pointer types
5//! (`CppBox`, `Ptr`, `MutPtr`, `Ref`, `MutRef`) automatically implement `PartialOrd`.
6
7/// Represents C++'s `operator<`.
8pub trait Lt<Rhs: ?Sized = Self> {
9 /// This method tests less than (for `self` and `other`) and is used by the `<` operator.
10 fn lt(&self, other: &Rhs) -> bool;
11}
12
13/// Represents C++'s `operator<=`.
14pub trait Le<Rhs: ?Sized = Self> {
15 /// This method tests less than or equal to (for `self` and `other`) and is used by the `<=`
16 fn le(&self, other: &Rhs) -> bool;
17}
18
19/// Represents C++'s `operator>`.
20pub trait Gt<Rhs: ?Sized = Self> {
21 /// This method tests greater than (for `self` and `other`) and is used by the `>` operator.
22 fn gt(&self, other: &Rhs) -> bool;
23}
24
25/// Represents C++'s `operator>=`.
26pub trait Ge<Rhs: ?Sized = Self> {
27 /// This method tests greater than or equal to (for `self` and `other`) and is used by the `>=`
28 /// operator.
29 fn ge(&self, other: &Rhs) -> bool;
30}