Skip to content

Commit 26b8b06

Browse files
authored
Merge pull request #26 from tcharding/12-30-docs-section
Further improve docs
2 parents 8499fa5 + 288e168 commit 26b8b06

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/lib.rs

+29-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
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.
@@ -38,6 +38,8 @@
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+
/// ```
5985
pub 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

Comments
 (0)