From 4f7dbe68f7ca6b20bddfad6a05418355f7f6d673 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 30 Dec 2024 07:46:39 +1100 Subject: [PATCH 1/4] Add hyperlink to example file Link to the file on GitHub. --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index c7218e6..9adddf4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! `PartialOrd` and `Ord` are often useful and/or required. For example, [`Ordered`] allows one to //! use such a type as a key in a `BTreeMap` (which requires ordered keys). //! -//! For a full example see `examples/point.rs`. +//! For a full example see [`examples/point.rs`]. //! //! # Examples //! @@ -38,6 +38,8 @@ //! point: Ordered, //! } //! ``` +//! +//! [`examples/point.rs`]: #![no_std] // Experimental features we need. From 8b1cafc2affdc52a5839a32372d5705b898eab12 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 30 Dec 2024 07:49:32 +1100 Subject: [PATCH 2/4] Add examples docs to ArbitraryOrd Copy a minimal version of the docs found throughout the crate onto the single public trait. --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 9adddf4..42352e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,6 +58,30 @@ use core::ops::{Deref, DerefMut}; /// /// More specifically, this trait is for types that perform either a partial or /// total order but semantically it is nonsensical. +/// +/// # Examples +/// +/// ``` +/// # #![allow(unused)] // Because of `Adt`. +/// use core::{cmp::Ordering, fmt}; +/// use ordered::{ArbitraryOrd, Ordered}; +/// +/// /// A point in 2D space. +/// /// +/// /// We do not want users to be able to write `a < b` because it is not well defined. +/// #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +/// struct Point { +/// x: u32, +/// y: u32, +/// } +/// +/// impl ArbitraryOrd for Point { +/// fn arbitrary_cmp(&self, other: &Self) -> Ordering { +/// // Just use whatever order tuple cmp gives us. +/// (self.x, self.y).cmp(&(other.x, other.y)) +/// } +/// } +/// ``` pub trait ArbitraryOrd: Eq + PartialEq { /// Implements a meaningless, arbitrary ordering. fn arbitrary_cmp(&self, other: &Self) -> Ordering; From 6bda7c94ae951e47320a23513ed57d9464176979 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 30 Dec 2024 07:52:00 +1100 Subject: [PATCH 3/4] Do not import fmt in rustdocs We don't need `fmt`, it was accidentally copied from the code in `examples/point.rs`. --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 42352e5..4f7801b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ //! //! ``` //! # #![allow(unused)] // Because of `Adt`. -//! use core::{cmp::Ordering, fmt}; +//! use core::cmp::Ordering; //! use ordered::{ArbitraryOrd, Ordered}; //! //! /// A point in 2D space. @@ -63,7 +63,7 @@ use core::ops::{Deref, DerefMut}; /// /// ``` /// # #![allow(unused)] // Because of `Adt`. -/// use core::{cmp::Ordering, fmt}; +/// use core::cmp::Ordering; /// use ordered::{ArbitraryOrd, Ordered}; /// /// /// A point in 2D space. @@ -93,7 +93,7 @@ pub trait ArbitraryOrd: Eq + PartialEq { /// /// ``` /// # #![allow(unused)] // Because of `Adt`. -/// use core::{cmp::Ordering, fmt}; +/// use core::cmp::Ordering; /// use ordered::{ArbitraryOrd, Ordered}; /// /// /// A point in 2D space. From 288e16876132b41efc48e26f304e25df7f5b1ad2 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Mon, 30 Dec 2024 07:53:40 +1100 Subject: [PATCH 4/4] Remove unused import of Ordered --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 4f7801b..d51cffa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,7 @@ use core::ops::{Deref, DerefMut}; /// ``` /// # #![allow(unused)] // Because of `Adt`. /// use core::cmp::Ordering; -/// use ordered::{ArbitraryOrd, Ordered}; +/// use ordered::ArbitraryOrd; /// /// /// A point in 2D space. /// ///