Skip to content

Commit 439a193

Browse files
authored
Merge pull request rust-bitcoin#24 from tcharding/12-30-docs
Improve rustdocs
2 parents 5c6ec75 + 809b8a6 commit 439a193

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

examples/point.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ fn main() {
1717

1818
println!();
1919
println!("Looking in map for key: {}", a);
20-
let found = map.get(Ordered::from_ref(&a)).expect("failed to look up key");
20+
21+
let found = map.get(Ordered::from_ref(&a)).expect("handle item not found");
22+
2123
println!("Found it, with value: {}", found);
2224
}
2325

src/lib.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// SPDX-License-Identifier: CC0-1.0
22

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`.
510
//!
611
//! # Examples
712
//!
@@ -26,12 +31,6 @@
2631
//! }
2732
//! }
2833
//!
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-
//!
3534
//! /// `Ordered` allows users to derive `PartialOrd` on types that include a `Point`.
3635
//! #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
3736
//! struct Adt {
@@ -87,17 +86,11 @@ pub trait ArbitraryOrd: Eq + PartialEq {
8786
/// }
8887
/// }
8988
///
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-
///
9689
/// let point = Point { x: 0, y: 1 };
9790
/// let ordered = Ordered(point);
9891
///
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`.
10194
/// ```
10295
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
10396
#[repr(transparent)]

0 commit comments

Comments
 (0)