|
14 | 14 | //! by the compiler to implement comparison operators. Rust programs may |
15 | 15 | //! implement `PartialOrd` to overload the `<`, `<=`, `>`, and `>=` operators, |
16 | 16 | //! and may implement `PartialEq` to overload the `==` and `!=` operators. |
| 17 | +//! |
| 18 | +//! # Examples |
| 19 | +//! |
| 20 | +//! ``` |
| 21 | +//! let x: u32 = 0; |
| 22 | +//! let y: u32 = 1; |
| 23 | +//! |
| 24 | +//! // these two lines are equivalent |
| 25 | +//! assert_eq!(x < y, true); |
| 26 | +//! assert_eq!(x.lt(&y), true); |
| 27 | +//! |
| 28 | +//! // these two lines are also equivalent |
| 29 | +//! assert_eq!(x == y, false); |
| 30 | +//! assert_eq!(x.eq(&y), false); |
| 31 | +//! ``` |
17 | 32 |
|
18 | 33 | #![stable(feature = "rust1", since = "1.0.0")] |
19 | 34 |
|
@@ -44,6 +59,16 @@ use option::Option::{self, Some}; |
44 | 59 | /// only if `a != b`. |
45 | 60 | /// |
46 | 61 | /// This trait can be used with `#[derive]`. |
| 62 | +/// |
| 63 | +/// # Examples |
| 64 | +/// |
| 65 | +/// ``` |
| 66 | +/// let x: u32 = 0; |
| 67 | +/// let y: u32 = 1; |
| 68 | +/// |
| 69 | +/// assert_eq!(x == y, false); |
| 70 | +/// assert_eq!(x.eq(&y), false); |
| 71 | +/// ``` |
47 | 72 | #[lang = "eq"] |
48 | 73 | #[stable(feature = "rust1", since = "1.0.0")] |
49 | 74 | pub trait PartialEq<Rhs: ?Sized = Self> { |
@@ -226,6 +251,16 @@ impl PartialOrd for Ordering { |
226 | 251 | /// |
227 | 252 | /// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering |
228 | 253 | /// based on the top-to-bottom declaration order of the struct's members. |
| 254 | +/// |
| 255 | +/// # Examples |
| 256 | +/// |
| 257 | +/// ``` |
| 258 | +/// let x : u32 = 0; |
| 259 | +/// let y : u32 = 1; |
| 260 | +/// |
| 261 | +/// assert_eq!(x < y, true); |
| 262 | +/// assert_eq!(x.lt(&y), true); |
| 263 | +/// ``` |
229 | 264 | #[lang = "ord"] |
230 | 265 | #[stable(feature = "rust1", since = "1.0.0")] |
231 | 266 | pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> { |
|
0 commit comments