Skip to content

Commit 4ed70c2

Browse files
committed
Rollup merge of rust-lang#32322 - GuillaumeGomez:cmp_doc, r=steveklabnik
Add doc examples Fixes rust-lang#29347 r? @steveklabnik
2 parents 690f160 + 3aac461 commit 4ed70c2

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/libcore/cmp.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
//! by the compiler to implement comparison operators. Rust programs may
1515
//! implement `PartialOrd` to overload the `<`, `<=`, `>`, and `>=` operators,
1616
//! 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+
//! ```
1732
1833
#![stable(feature = "rust1", since = "1.0.0")]
1934

@@ -44,6 +59,16 @@ use option::Option::{self, Some};
4459
/// only if `a != b`.
4560
///
4661
/// 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+
/// ```
4772
#[lang = "eq"]
4873
#[stable(feature = "rust1", since = "1.0.0")]
4974
pub trait PartialEq<Rhs: ?Sized = Self> {
@@ -226,6 +251,16 @@ impl PartialOrd for Ordering {
226251
///
227252
/// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering
228253
/// 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+
/// ```
229264
#[lang = "ord"]
230265
#[stable(feature = "rust1", since = "1.0.0")]
231266
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {

0 commit comments

Comments
 (0)