From 3aac461d4053e8f8479d72a3a4c2f26a1b13a5aa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 14 Mar 2016 16:43:55 +0100 Subject: [PATCH] Add doc examples --- src/libcore/cmp.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 042cbea64bd26..49aa0238a996a 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -14,6 +14,21 @@ //! by the compiler to implement comparison operators. Rust programs may //! implement `PartialOrd` to overload the `<`, `<=`, `>`, and `>=` operators, //! and may implement `PartialEq` to overload the `==` and `!=` operators. +//! +//! # Examples +//! +//! ``` +//! let x: u32 = 0; +//! let y: u32 = 1; +//! +//! // these two lines are equivalent +//! assert_eq!(x < y, true); +//! assert_eq!(x.lt(&y), true); +//! +//! // these two lines are also equivalent +//! assert_eq!(x == y, false); +//! assert_eq!(x.eq(&y), false); +//! ``` #![stable(feature = "rust1", since = "1.0.0")] @@ -44,6 +59,16 @@ use option::Option::{self, Some}; /// only if `a != b`. /// /// This trait can be used with `#[derive]`. +/// +/// # Examples +/// +/// ``` +/// let x: u32 = 0; +/// let y: u32 = 1; +/// +/// assert_eq!(x == y, false); +/// assert_eq!(x.eq(&y), false); +/// ``` #[lang = "eq"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialEq { @@ -226,6 +251,16 @@ impl PartialOrd for Ordering { /// /// This trait can be used with `#[derive]`. When `derive`d, it will produce an ordering /// based on the top-to-bottom declaration order of the struct's members. +/// +/// # Examples +/// +/// ``` +/// let x : u32 = 0; +/// let y : u32 = 1; +/// +/// assert_eq!(x < y, true); +/// assert_eq!(x.lt(&y), true); +/// ``` #[lang = "ord"] #[stable(feature = "rust1", since = "1.0.0")] pub trait PartialOrd: PartialEq {