Skip to content

Commit 2281290

Browse files
Add missing urls and small nits
1 parent aed6410 commit 2281290

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed

src/libcollections/vec_deque.rs

+58-25
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ const MAXIMUM_ZST_CAPACITY: usize = 1 << (64 - 1); // Largest possible power of
4646
/// `VecDeque` is a growable ring buffer, which can be used as a double-ended
4747
/// queue efficiently.
4848
///
49-
/// The "default" usage of this type as a queue is to use `push_back` to add to
50-
/// the queue, and `pop_front` to remove from the queue. `extend` and `append`
49+
/// The "default" usage of this type as a queue is to use [`push_back`] to add to
50+
/// the queue, and [`pop_front`] to remove from the queue. [`extend`] and [`append`]
5151
/// push onto the back in this manner, and iterating over `VecDeque` goes front
5252
/// to back.
53+
///
54+
/// [`push_back`]: #method.push_back
55+
/// [`pop_front`]: #method.pop_front
56+
/// [`extend`]: #method.extend
57+
/// [`append`]: #method.append
5358
#[stable(feature = "rust1", since = "1.0.0")]
5459
pub struct VecDeque<T> {
5560
// tail and head are pointers into the buffer. Tail always points
@@ -92,13 +97,13 @@ impl<T> Default for VecDeque<T> {
9297
}
9398

9499
impl<T> VecDeque<T> {
95-
/// Marginally more convenient
100+
/// Marginally more convenient.
96101
#[inline]
97102
fn ptr(&self) -> *mut T {
98103
self.buf.ptr()
99104
}
100105

101-
/// Marginally more convenient
106+
/// Marginally more convenient.
102107
#[inline]
103108
fn cap(&self) -> usize {
104109
if mem::size_of::<T>() == 0 {
@@ -109,19 +114,19 @@ impl<T> VecDeque<T> {
109114
}
110115
}
111116

112-
/// Turn ptr into a slice
117+
/// Turn ptr into a slice.
113118
#[inline]
114119
unsafe fn buffer_as_slice(&self) -> &[T] {
115120
slice::from_raw_parts(self.ptr(), self.cap())
116121
}
117122

118-
/// Turn ptr into a mut slice
123+
/// Turn ptr into a mut slice.
119124
#[inline]
120125
unsafe fn buffer_as_mut_slice(&mut self) -> &mut [T] {
121126
slice::from_raw_parts_mut(self.ptr(), self.cap())
122127
}
123128

124-
/// Moves an element out of the buffer
129+
/// Moves an element out of the buffer.
125130
#[inline]
126131
unsafe fn buffer_read(&mut self, off: usize) -> T {
127132
ptr::read(self.ptr().offset(off as isize))
@@ -133,7 +138,7 @@ impl<T> VecDeque<T> {
133138
ptr::write(self.ptr().offset(off as isize), value);
134139
}
135140

136-
/// Returns true if and only if the buffer is at capacity
141+
/// Returns true if and only if the buffer is at capacity.
137142
#[inline]
138143
fn is_full(&self) -> bool {
139144
self.cap() - self.len() == 1
@@ -506,12 +511,15 @@ impl<T> VecDeque<T> {
506511
/// given `VecDeque`. Does nothing if the capacity is already sufficient.
507512
///
508513
/// Note that the allocator may give the collection more space than it requests. Therefore
509-
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
514+
/// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
510515
/// insertions are expected.
511516
///
512517
/// # Panics
513518
///
514-
/// Panics if the new capacity overflows `usize`.
519+
/// Panics if the new capacity overflows [`usize`].
520+
///
521+
/// [`reserve`]: #method.reserve
522+
/// [`usize`]: ../../std/primitive.usize.html
515523
///
516524
/// # Examples
517525
///
@@ -532,7 +540,9 @@ impl<T> VecDeque<T> {
532540
///
533541
/// # Panics
534542
///
535-
/// Panics if the new capacity overflows `usize`.
543+
/// Panics if the new capacity overflows [`usize`].
544+
///
545+
/// [`usize`]: ../../std/primitive.usize.html
536546
///
537547
/// # Examples
538548
///
@@ -788,7 +798,7 @@ impl<T> VecDeque<T> {
788798
count(self.tail, self.head, self.cap())
789799
}
790800

791-
/// Returns true if the buffer contains no elements
801+
/// Returns true if the buffer contains no elements.
792802
///
793803
/// # Examples
794804
///
@@ -812,14 +822,17 @@ impl<T> VecDeque<T> {
812822
/// consumed until the end.
813823
///
814824
/// Note 2: It is unspecified how many elements are removed from the deque,
815-
/// if the `Drain` value is not dropped, but the borrow it holds expires
816-
/// (eg. due to mem::forget).
825+
/// if the [`Drain`] value is not dropped, but the borrow it holds expires
826+
/// (eg. due to [`mem::forget`]).
817827
///
818828
/// # Panics
819829
///
820830
/// Panics if the starting point is greater than the end point or if
821831
/// the end point is greater than the length of the vector.
822832
///
833+
/// [`Drain`]: ../../std/collections/vec_deque/struct.Drain.html
834+
/// [`mem::forget`]: ../../std/mem/fn.forget.html
835+
///
823836
/// # Examples
824837
///
825838
/// ```
@@ -941,9 +954,11 @@ impl<T> VecDeque<T> {
941954
a.contains(x) || b.contains(x)
942955
}
943956

944-
/// Provides a reference to the front element, or `None` if the sequence is
957+
/// Provides a reference to the front element, or [`None`] if the sequence is
945958
/// empty.
946959
///
960+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
961+
///
947962
/// # Examples
948963
///
949964
/// ```
@@ -965,9 +980,11 @@ impl<T> VecDeque<T> {
965980
}
966981
}
967982

968-
/// Provides a mutable reference to the front element, or `None` if the
983+
/// Provides a mutable reference to the front element, or [`None`] if the
969984
/// sequence is empty.
970985
///
986+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
987+
///
971988
/// # Examples
972989
///
973990
/// ```
@@ -993,9 +1010,11 @@ impl<T> VecDeque<T> {
9931010
}
9941011
}
9951012

996-
/// Provides a reference to the back element, or `None` if the sequence is
1013+
/// Provides a reference to the back element, or [`None`] if the sequence is
9971014
/// empty.
9981015
///
1016+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1017+
///
9991018
/// # Examples
10001019
///
10011020
/// ```
@@ -1017,9 +1036,11 @@ impl<T> VecDeque<T> {
10171036
}
10181037
}
10191038

1020-
/// Provides a mutable reference to the back element, or `None` if the
1039+
/// Provides a mutable reference to the back element, or [`None`] if the
10211040
/// sequence is empty.
10221041
///
1042+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1043+
///
10231044
/// # Examples
10241045
///
10251046
/// ```
@@ -1046,9 +1067,11 @@ impl<T> VecDeque<T> {
10461067
}
10471068
}
10481069

1049-
/// Removes the first element and returns it, or `None` if the sequence is
1070+
/// Removes the first element and returns it, or [`None`] if the sequence is
10501071
/// empty.
10511072
///
1073+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1074+
///
10521075
/// # Examples
10531076
///
10541077
/// ```
@@ -1131,9 +1154,11 @@ impl<T> VecDeque<T> {
11311154
unsafe { self.buffer_write(head, value) }
11321155
}
11331156

1134-
/// Removes the last element from a buffer and returns it, or `None` if
1157+
/// Removes the last element from a buffer and returns it, or [`None`] if
11351158
/// it is empty.
11361159
///
1160+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1161+
///
11371162
/// # Examples
11381163
///
11391164
/// ```
@@ -1166,10 +1191,12 @@ impl<T> VecDeque<T> {
11661191
///
11671192
/// This does not preserve ordering, but is O(1).
11681193
///
1169-
/// Returns `None` if `index` is out of bounds.
1194+
/// Returns [`None`] if `index` is out of bounds.
11701195
///
11711196
/// Element at index 0 is the front of the queue.
11721197
///
1198+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1199+
///
11731200
/// # Examples
11741201
///
11751202
/// ```
@@ -1201,10 +1228,12 @@ impl<T> VecDeque<T> {
12011228
///
12021229
/// This does not preserve ordering, but is O(1).
12031230
///
1204-
/// Returns `None` if `index` is out of bounds.
1231+
/// Returns [`None`] if `index` is out of bounds.
12051232
///
12061233
/// Element at index 0 is the front of the queue.
12071234
///
1235+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1236+
///
12081237
/// # Examples
12091238
///
12101239
/// ```
@@ -1238,7 +1267,7 @@ impl<T> VecDeque<T> {
12381267
///
12391268
/// # Panics
12401269
///
1241-
/// Panics if `index` is greater than `VecDeque`'s length
1270+
/// Panics if `index` is greater than `VecDeque`'s length.
12421271
///
12431272
/// # Examples
12441273
///
@@ -1463,10 +1492,12 @@ impl<T> VecDeque<T> {
14631492
/// Removes and returns the element at `index` from the `VecDeque`.
14641493
/// Whichever end is closer to the removal point will be moved to make
14651494
/// room, and all the affected elements will be moved to new positions.
1466-
/// Returns `None` if `index` is out of bounds.
1495+
/// Returns [`None`] if `index` is out of bounds.
14671496
///
14681497
/// Element at index 0 is the front of the queue.
14691498
///
1499+
/// [`None`]: ../../std/option/enum.Option.html#variant.None
1500+
///
14701501
/// # Examples
14711502
///
14721503
/// ```
@@ -1709,7 +1740,9 @@ impl<T> VecDeque<T> {
17091740
///
17101741
/// # Panics
17111742
///
1712-
/// Panics if the new number of elements in self overflows a `usize`.
1743+
/// Panics if the new number of elements in self overflows a [`usize`].
1744+
///
1745+
/// [`usize`]: ../../std/primitive.usize.html
17131746
///
17141747
/// # Examples
17151748
///

src/libstd/collections/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! processing. They are exceptionally good at doing what they do. All the other
2121
//! collections in the standard library have specific use cases where they are
2222
//! the optimal choice, but these cases are borderline *niche* in comparison.
23-
//! Even when `Vec` and `HashMap` are technically suboptimal, they're probably a
23+
//! Even when [`Vec`] and [`HashMap`] are technically suboptimal, they're probably a
2424
//! good enough choice to get started.
2525
//!
2626
//! Rust's collections can be grouped into four major categories:
@@ -37,6 +37,7 @@
3737
//! individual collections can be found on their own documentation pages.
3838
//!
3939
//! ### Use a `Vec` when:
40+
//!
4041
//! * You want to collect items up to be processed or sent elsewhere later, and
4142
//! don't care about any properties of the actual values being stored.
4243
//! * You want a sequence of elements in a particular order, and will only be
@@ -46,31 +47,36 @@
4647
//! * You want a heap-allocated array.
4748
//!
4849
//! ### Use a `VecDeque` when:
50+
//!
4951
//! * You want a [`Vec`] that supports efficient insertion at both ends of the
5052
//! sequence.
5153
//! * You want a queue.
5254
//! * You want a double-ended queue (deque).
5355
//!
5456
//! ### Use a `LinkedList` when:
57+
//!
5558
//! * You want a [`Vec`] or [`VecDeque`] of unknown size, and can't tolerate
5659
//! amortization.
5760
//! * You want to efficiently split and append lists.
5861
//! * You are *absolutely* certain you *really*, *truly*, want a doubly linked
5962
//! list.
6063
//!
6164
//! ### Use a `HashMap` when:
65+
//!
6266
//! * You want to associate arbitrary keys with an arbitrary value.
6367
//! * You want a cache.
6468
//! * You want a map, with no extra functionality.
6569
//!
6670
//! ### Use a `BTreeMap` when:
71+
//!
6772
//! * You're interested in what the smallest or largest key-value pair is.
6873
//! * You want to find the largest or smallest key that is smaller or larger
6974
//! than something.
7075
//! * You want to be able to get all of the entries in order on-demand.
7176
//! * You want a sorted map.
7277
//!
7378
//! ### Use the `Set` variant of any of these `Map`s when:
79+
//!
7480
//! * You just want to remember which keys you've seen.
7581
//! * There is no meaningful value to associate with your keys.
7682
//! * You just want a set.
@@ -451,7 +457,7 @@ pub mod hash_map {
451457
#[stable(feature = "rust1", since = "1.0.0")]
452458
pub mod hash_set {
453459
//! An implementation of a hash set using the underlying representation of a
454-
//! HashMap where the value is ().
460+
//! `HashMap` where the value is ().
455461
#[stable(feature = "rust1", since = "1.0.0")]
456462
pub use super::hash::set::*;
457463
}

0 commit comments

Comments
 (0)