Skip to content

Commit 848c784

Browse files
committed
Add more links in documentation
Following rust-lang/rust#89010, add links to referenced items in the parts of this crate's documentation that unique here and not found in `std`.
1 parent 8326532 commit 848c784

File tree

3 files changed

+64
-39
lines changed

3 files changed

+64
-39
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
![Rust](https://github.com/sekineh/binary-heap-plus-rs/workflows/Rust/badge.svg)
44

5-
Enhancement over Rust's `std::collections::BinaryHeap`.
5+
Enhancement over Rust's
6+
[`std::collections::BinaryHeap`](https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html).
67

78
It supports the following heaps and still maintains backward compatibility.
89
- Max heap
@@ -25,8 +26,8 @@ This crate requires Rust 1.36.0 or later.
2526

2627
# Changes
2728

28-
See CHANGELOG.md.
29-
https://github.com/sekineh/binary-heap-plus-rs/blob/master/CHANGELOG.md
29+
See
30+
[CHANGELOG.md](https://github.com/sekineh/binary-heap-plus-rs/blob/master/CHANGELOG.md).
3031

3132
# Thanks
3233

src/binary_heap.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,31 +432,37 @@ impl<T: fmt::Debug, C: Compare<T>> fmt::Debug for BinaryHeap<T, C> {
432432
}
433433

434434
impl<T, C: Compare<T> + Default> BinaryHeap<T, C> {
435-
/// Generic constructor for `BinaryHeap` from `Vec`.
435+
/// Generic constructor for `BinaryHeap` from [`Vec`].
436436
///
437437
/// Because `BinaryHeap` stores the elements in its internal `Vec`,
438438
/// it's natural to construct it from `Vec`.
439+
///
440+
/// [`Vec`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html
439441
pub fn from_vec(vec: Vec<T>) -> Self {
440442
BinaryHeap::from_vec_cmp(vec, C::default())
441443
}
442444
}
443445

444446
impl<T, C: Compare<T>> BinaryHeap<T, C> {
445-
/// Generic constructor for `BinaryHeap` from `Vec` and comparator.
447+
/// Generic constructor for `BinaryHeap` from [`Vec`] and comparator.
446448
///
447449
/// Because `BinaryHeap` stores the elements in its internal `Vec`,
448450
/// it's natural to construct it from `Vec`.
451+
///
452+
/// [`Vec`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html
449453
pub fn from_vec_cmp(vec: Vec<T>, cmp: C) -> Self {
450454
unsafe { BinaryHeap::from_vec_cmp_raw(vec, cmp, true) }
451455
}
452456

453-
/// Generic constructor for `BinaryHeap` from `Vec` and comparator.
457+
/// Generic constructor for `BinaryHeap` from [`Vec`] and comparator.
454458
///
455459
/// Because `BinaryHeap` stores the elements in its internal `Vec`,
456460
/// it's natural to construct it from `Vec`.
457461
///
458462
/// # Safety
459463
/// User is responsible for providing valid `rebuild` value.
464+
///
465+
/// [`Vec`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html
460466
pub unsafe fn from_vec_cmp_raw(vec: Vec<T>, cmp: C, rebuild: bool) -> Self {
461467
let mut heap = BinaryHeap { data: vec, cmp };
462468
if rebuild && !heap.data.is_empty() {

src/lib.rs

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,76 @@
1-
//! This crate provides `BinaryHeap` which is backward-compatible with `std::collections::BinaryHeap`.
1+
//! This crate provides [`BinaryHeap`] which is backward-compatible with
2+
//! [`std::collections::BinaryHeap`].
23
//!
34
//! Added features include:
45
//! * Heaps other than max heap.
5-
//! * Optional `serde` feature.
6+
//! * Optional [`serde`] feature.
7+
//!
8+
//! [`BinaryHeap`]: struct.BinaryHeap.html
9+
//! [`std::collections::BinaryHeap`]:
10+
//! https://doc.rust-lang.org/stable/std/collections/struct.BinaryHeap.html
11+
//! [`serde`]: https://docs.serde.rs/serde/
612
//!
713
//! # Quick start
814
//!
915
//! ## Max/Min Heap
1016
//!
11-
//! For max heap, `BiaryHeap::from_vec()` is the most versatile way to create a heap.
17+
//! For max heap, [`BinaryHeap::from_vec()`] is the most versatile way to create a heap.
1218
//!
1319
//! ```rust
14-
//! use binary_heap_plus::*;
20+
//! use binary_heap_plus::*;
1521
//!
16-
//! // max heap
17-
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(vec![]);
18-
//! // max heap with initial capacity
19-
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(Vec::with_capacity(16));
20-
//! // max heap from iterator
21-
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec((0..42).collect());
22-
//! assert_eq!(h.pop(), Some(41));
22+
//! // max heap
23+
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(vec![]);
24+
//! // max heap with initial capacity
25+
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec(Vec::with_capacity(16));
26+
//! // max heap from iterator
27+
//! let mut h: BinaryHeap<i32> = BinaryHeap::from_vec((0..42).collect());
28+
//! assert_eq!(h.pop(), Some(41));
2329
//! ```
2430
//!
2531
//! Min heap is similar, but requires type annotation.
2632
//!
2733
//! ```rust
28-
//! use binary_heap_plus::*;
34+
//! use binary_heap_plus::*;
2935
//!
30-
//! // min heap
31-
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(vec![]);
32-
//! // min heap with initial capacity
33-
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(Vec::with_capacity(16));
34-
//! // min heap from iterator
35-
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec((0..42).collect());
36-
//! assert_eq!(h.pop(), Some(0));
36+
//! // min heap
37+
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(vec![]);
38+
//! // min heap with initial capacity
39+
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec(Vec::with_capacity(16));
40+
//! // min heap from iterator
41+
//! let mut h: BinaryHeap<i32, MinComparator> = BinaryHeap::from_vec((0..42).collect());
42+
//! assert_eq!(h.pop(), Some(0));
3743
//! ```
3844
//!
45+
//! [`BinaryHeap::from_vec()`]: struct.BinaryHeap.html#method.from_vec
46+
//!
3947
//! ## Custom Heap
4048
//!
41-
//! For custom heap, `BinaryHeap::from_vec_cmp()` works in a similar way to max/min heap. The only difference is that you add the comparator closure with apropriate signature.
49+
//! For custom heap, [`BinaryHeap::from_vec_cmp()`] works in a similar way to max/min heap. The
50+
//! only difference is that you add the comparator closure with apropriate signature.
4251
//!
4352
//! ```rust
44-
//! use binary_heap_plus::*;
53+
//! use binary_heap_plus::*;
4554
//!
46-
//! // custom heap: ordered by second value (_.1) of the tuples; min first
47-
//! let mut h = BinaryHeap::from_vec_cmp(
48-
//! vec![(1, 5), (3, 2), (2, 3)],
49-
//! |a: &(i32, i32), b: &(i32, i32)| b.1.cmp(&a.1), // comparator closure here
50-
//! );
51-
//! assert_eq!(h.pop(), Some((3, 2)));
55+
//! // custom heap: ordered by second value (_.1) of the tuples; min first
56+
//! let mut h = BinaryHeap::from_vec_cmp(
57+
//! vec![(1, 5), (3, 2), (2, 3)],
58+
//! |a: &(i32, i32), b: &(i32, i32)| b.1.cmp(&a.1), // comparator closure here
59+
//! );
60+
//! assert_eq!(h.pop(), Some((3, 2)));
5261
//! ```
5362
//!
63+
//! [`BinaryHeap::from_vec_cmp()`]: struct.BinaryHeap.html#method.from_vec_cmp
64+
//!
5465
//! # Constructers
5566
//!
5667
//! ## Generic methods to create different kind of heaps from initial `vec` data.
5768
//!
58-
//! * `BinaryHeap::from_vec(vec)`
59-
//! * `BinaryHeap::from_vec_cmp(vec, cmp)`
69+
//! * [`BinaryHeap::from_vec`]`(vec)`
70+
//! * [`BinaryHeap::from_vec_cmp`]`(vec, cmp)`
71+
//!
72+
//! [`BinaryHeap::from_vec`]: struct.BinaryHeap.html#method.from_vec
73+
//! [`BinaryHeap::from_vec_cmp`]: struct.BinaryHeap.html#method.from_vec_cmp
6074
//!
6175
//! ```
6276
//! use binary_heap_plus::*;
@@ -87,11 +101,15 @@
87101
//!
88102
//! ## Dedicated methods to create different kind of heaps
89103
//!
90-
//! * `BinaryHeap::new()` creates a max heap.
91-
//! * `BinaryHeap::new_min()` creates a min heap.
92-
//! * `BinaryHeap::new_by()` creates a heap sorted by the given closure.
93-
//! * `BinaryHeap::new_by_key()` creates a heap sorted by the key generated by the given closure.
104+
//! * [`BinaryHeap::new()`] creates a max heap.
105+
//! * [`BinaryHeap::new_min()`] creates a min heap.
106+
//! * [`BinaryHeap::new_by()`] creates a heap sorted by the given closure.
107+
//! * [`BinaryHeap::new_by_key()`] creates a heap sorted by the key generated by the given closure.
94108
//!
109+
//! [`BinaryHeap::new()`]: struct.BinaryHeap.html#method.new
110+
//! [`BinaryHeap::new_min()`]: struct.BinaryHeap.html#method.new_min
111+
//! [`BinaryHeap::new_by()`]: struct.BinaryHeap.html#method.new_by
112+
//! [`BinaryHeap::new_by_key()`]: struct.BinaryHeap.html#method.new_by_key
95113
96114
mod binary_heap;
97115
pub use crate::binary_heap::*;

0 commit comments

Comments
 (0)