66//! `PartialOrd` and `Ord` are often useful and/or required. For example, [`Ordered`] allows one to
77//! use such a type as a key in a `BTreeMap` (which requires ordered keys).
88//!
9- //! For a full example see `examples/point.rs`.
9+ //! For a full example see [ `examples/point.rs`] .
1010//!
1111//! # Examples
1212//!
1313//! ```
1414//! # #![allow(unused)] // Because of `Adt`.
15- //! use core::{ cmp::Ordering, fmt} ;
15+ //! use core::cmp::Ordering;
1616//! use ordered::{ArbitraryOrd, Ordered};
1717//!
1818//! /// A point in 2D space.
3838//! point: Ordered<Point>,
3939//! }
4040//! ```
41+ //!
42+ //! [`examples/point.rs`]: <https://github.com/rust-bitcoin/rust-ordered/blob/master/examples/point.rs>
4143
4244#![ no_std]
4345// Experimental features we need.
@@ -56,6 +58,30 @@ use core::ops::{Deref, DerefMut};
5658///
5759/// More specifically, this trait is for types that perform either a partial or
5860/// 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+ /// ```
5985pub trait ArbitraryOrd : Eq + PartialEq {
6086 /// Implements a meaningless, arbitrary ordering.
6187 fn arbitrary_cmp ( & self , other : & Self ) -> Ordering ;
@@ -67,7 +93,7 @@ pub trait ArbitraryOrd: Eq + PartialEq {
6793///
6894/// ```
6995/// # #![allow(unused)] // Because of `Adt`.
70- /// use core::{ cmp::Ordering, fmt} ;
96+ /// use core::cmp::Ordering;
7197/// use ordered::{ArbitraryOrd, Ordered};
7298///
7399/// /// A point in 2D space.
0 commit comments