6
6
//! `PartialOrd` and `Ord` are often useful and/or required. For example, [`Ordered`] allows one to
7
7
//! use such a type as a key in a `BTreeMap` (which requires ordered keys).
8
8
//!
9
- //! For a full example see `examples/point.rs`.
9
+ //! For a full example see [ `examples/point.rs`] .
10
10
//!
11
11
//! # Examples
12
12
//!
13
13
//! ```
14
14
//! # #![allow(unused)] // Because of `Adt`.
15
- //! use core::{ cmp::Ordering, fmt} ;
15
+ //! use core::cmp::Ordering;
16
16
//! use ordered::{ArbitraryOrd, Ordered};
17
17
//!
18
18
//! /// A point in 2D space.
38
38
//! point: Ordered<Point>,
39
39
//! }
40
40
//! ```
41
+ //!
42
+ //! [`examples/point.rs`]: <https://github.com/rust-bitcoin/rust-ordered/blob/master/examples/point.rs>
41
43
42
44
#![ no_std]
43
45
// Experimental features we need.
@@ -56,6 +58,30 @@ use core::ops::{Deref, DerefMut};
56
58
///
57
59
/// More specifically, this trait is for types that perform either a partial or
58
60
/// total order but semantically it is nonsensical.
61
+ ///
62
+ /// # Examples
63
+ ///
64
+ /// ```
65
+ /// # #![allow(unused)] // Because of `Adt`.
66
+ /// use core::cmp::Ordering;
67
+ /// use ordered::ArbitraryOrd;
68
+ ///
69
+ /// /// A point in 2D space.
70
+ /// ///
71
+ /// /// We do not want users to be able to write `a < b` because it is not well defined.
72
+ /// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
73
+ /// struct Point {
74
+ /// x: u32,
75
+ /// y: u32,
76
+ /// }
77
+ ///
78
+ /// impl ArbitraryOrd for Point {
79
+ /// fn arbitrary_cmp(&self, other: &Self) -> Ordering {
80
+ /// // Just use whatever order tuple cmp gives us.
81
+ /// (self.x, self.y).cmp(&(other.x, other.y))
82
+ /// }
83
+ /// }
84
+ /// ```
59
85
pub trait ArbitraryOrd : Eq + PartialEq {
60
86
/// Implements a meaningless, arbitrary ordering.
61
87
fn arbitrary_cmp ( & self , other : & Self ) -> Ordering ;
@@ -67,7 +93,7 @@ pub trait ArbitraryOrd: Eq + PartialEq {
67
93
///
68
94
/// ```
69
95
/// # #![allow(unused)] // Because of `Adt`.
70
- /// use core::{ cmp::Ordering, fmt} ;
96
+ /// use core::cmp::Ordering;
71
97
/// use ordered::{ArbitraryOrd, Ordered};
72
98
///
73
99
/// /// A point in 2D space.
0 commit comments