|
1 | 1 | // SPDX-License-Identifier: CC0-1.0
|
2 | 2 |
|
3 |
| -//! Provides a wrapper for types that can technically implement `PartialOrd`/`Ord` |
4 |
| -//! but for semantic reasons it is nonsensical. |
| 3 | +//! Provides a wrapper for types that can technically implement `PartialOrd`/`Ord` but for semantic |
| 4 | +//! reasons it is nonsensical. |
| 5 | +//! |
| 6 | +//! `PartialOrd` and `Ord` are often useful and/or required. For example, [`Ordered`] allows one to |
| 7 | +//! use such a type as a key in a `BTreeMap` (which requires ordered keys). |
| 8 | +//! |
| 9 | +//! For a full example see `examples/point.rs`. |
5 | 10 | //!
|
6 | 11 | //! # Examples
|
7 | 12 | //!
|
|
26 | 31 | //! }
|
27 | 32 | //! }
|
28 | 33 | //!
|
29 |
| -//! impl fmt::Display for Point { |
30 |
| -//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
31 |
| -//! write!(f, "({}, {})", self.x, self.y) |
32 |
| -//! } |
33 |
| -//! } |
34 |
| -//! |
35 | 34 | //! /// `Ordered` allows users to derive `PartialOrd` on types that include a `Point`.
|
36 | 35 | //! #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
37 | 36 | //! struct Adt {
|
@@ -87,17 +86,11 @@ pub trait ArbitraryOrd: Eq + PartialEq {
|
87 | 86 | /// }
|
88 | 87 | /// }
|
89 | 88 | ///
|
90 |
| -/// impl fmt::Display for Point { |
91 |
| -/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
92 |
| -/// write!(f, "({}, {})", self.x, self.y) |
93 |
| -/// } |
94 |
| -/// } |
95 |
| -/// |
96 | 89 | /// let point = Point { x: 0, y: 1 };
|
97 | 90 | /// let ordered = Ordered(point);
|
98 | 91 | ///
|
99 |
| -/// assert_eq!(*ordered, ordered.into_inner()); // Explicitly deref or use `into_inner()`. |
100 |
| -/// assert_eq!(&ordered.0, ordered.as_ref()); // Use `AsRef` or `as_ref()`. |
| 92 | +/// assert_eq!(*ordered, point); // Use `ops::Deref`. |
| 93 | +/// assert_eq!(&ordered.0, ordered.as_ref()); // Use the public inner field or `AsRef`. |
101 | 94 | /// ```
|
102 | 95 | #[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
103 | 96 | #[repr(transparent)]
|
|
0 commit comments