Skip to content

Commit d64de94

Browse files
author
lukaramu
committed
Update std::collections' docs to use iterator (etc.) boilerplate
This greatly improves consistency.
1 parent ea37682 commit d64de94

File tree

7 files changed

+252
-50
lines changed

7 files changed

+252
-50
lines changed

src/libcollections/binary_heap.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,14 @@ pub struct BinaryHeap<T> {
218218
data: Vec<T>,
219219
}
220220

221-
/// A container object that represents the result of the [`peek_mut`] method
222-
/// on `BinaryHeap`. See its documentation for details.
221+
/// Object representing a mutable reference to the greatest item on a
222+
/// `BinaryHeap`.
223+
///
224+
/// This `struct` is created by the [`peek_mut`] method on [`BinaryHeap`]. See
225+
/// its documentation for more.
223226
///
224227
/// [`peek_mut`]: struct.BinaryHeap.html#method.peek_mut
228+
/// [`BinaryHeap`]: struct.BinaryHeap.html
225229
#[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
226230
pub struct PeekMut<'a, T: 'a + Ord> {
227231
heap: &'a mut BinaryHeap<T>,
@@ -971,7 +975,13 @@ impl<'a, T> Drop for Hole<'a, T> {
971975
}
972976
}
973977

974-
/// `BinaryHeap` iterator.
978+
/// An iterator over the elements of a `BinaryHeap`.
979+
///
980+
/// This `struct` is created by the [`iter`] method on [`BinaryHeap`]. See its
981+
/// documentation for more.
982+
///
983+
/// [`iter`]: struct.BinaryHeap.html#method.iter
984+
/// [`BinaryHeap`]: struct.BinaryHeap.html
975985
#[stable(feature = "rust1", since = "1.0.0")]
976986
pub struct Iter<'a, T: 'a> {
977987
iter: slice::Iter<'a, T>,
@@ -1027,7 +1037,13 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
10271037
#[unstable(feature = "fused", issue = "35602")]
10281038
impl<'a, T> FusedIterator for Iter<'a, T> {}
10291039

1030-
/// An iterator that moves out of a `BinaryHeap`.
1040+
/// An owning iterator over the elements of a `BinaryHeap`.
1041+
///
1042+
/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`]
1043+
/// (provided by the `IntoIterator` trait). See its documentation for more.
1044+
///
1045+
/// [`into_iter`]: struct.BinaryHeap.html#method.into_iter
1046+
/// [`BinaryHeap`]: struct.BinaryHeap.html
10311047
#[stable(feature = "rust1", since = "1.0.0")]
10321048
#[derive(Clone)]
10331049
pub struct IntoIter<T> {
@@ -1076,7 +1092,13 @@ impl<T> ExactSizeIterator for IntoIter<T> {
10761092
#[unstable(feature = "fused", issue = "35602")]
10771093
impl<T> FusedIterator for IntoIter<T> {}
10781094

1079-
/// An iterator that drains a `BinaryHeap`.
1095+
/// A draining iterator over the elements of a `BinaryHeap`.
1096+
///
1097+
/// This `struct` is created by the [`drain`] method on [`BinaryHeap`]. See its
1098+
/// documentation for more.
1099+
///
1100+
/// [`drain`]: struct.BinaryHeap.html#method.drain
1101+
/// [`BinaryHeap`]: struct.BinaryHeap.html
10801102
#[stable(feature = "drain", since = "1.6.0")]
10811103
#[derive(Debug)]
10821104
pub struct Drain<'a, T: 'a> {

src/libcollections/btree/map.rs

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,13 @@ impl<K, Q: ?Sized> super::Recover<Q> for BTreeMap<K, ()>
262262
}
263263
}
264264

265-
/// An iterator over a `BTreeMap`'s entries.
265+
/// An iterator over the entries of a `BTreeMap`.
266+
///
267+
/// This `struct` is created by the [`iter`] method on [`BTreeMap`]. See its
268+
/// documentation for more.
269+
///
270+
/// [`iter`]: struct.BTreeMap.html#method.iter
271+
/// [`BTreeMap`]: struct.BTreeMap.html
266272
#[stable(feature = "rust1", since = "1.0.0")]
267273
pub struct Iter<'a, K: 'a, V: 'a> {
268274
range: Range<'a, K, V>,
@@ -276,15 +282,27 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Iter<'a, K, V> {
276282
}
277283
}
278284

279-
/// A mutable iterator over a `BTreeMap`'s entries.
285+
/// A mutable iterator over the entries of a `BTreeMap`.
286+
///
287+
/// This `struct` is created by the [`iter_mut`] method on [`BTreeMap`]. See its
288+
/// documentation for more.
289+
///
290+
/// [`iter_mut`]: struct.BTreeMap.html#method.iter_mut
291+
/// [`BTreeMap`]: struct.BTreeMap.html
280292
#[stable(feature = "rust1", since = "1.0.0")]
281293
#[derive(Debug)]
282294
pub struct IterMut<'a, K: 'a, V: 'a> {
283295
range: RangeMut<'a, K, V>,
284296
length: usize,
285297
}
286298

287-
/// An owning iterator over a `BTreeMap`'s entries.
299+
/// An owning iterator over the entries of a `BTreeMap`.
300+
///
301+
/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`]
302+
/// (provided by the `IntoIterator` trait). See its documentation for more.
303+
///
304+
/// [`into_iter`]: struct.BTreeMap.html#method.into_iter
305+
/// [`BTreeMap`]: struct.BTreeMap.html
288306
#[stable(feature = "rust1", since = "1.0.0")]
289307
pub struct IntoIter<K, V> {
290308
front: Handle<NodeRef<marker::Owned, K, V, marker::Leaf>, marker::Edge>,
@@ -303,7 +321,13 @@ impl<K: fmt::Debug, V: fmt::Debug> fmt::Debug for IntoIter<K, V> {
303321
}
304322
}
305323

306-
/// An iterator over a `BTreeMap`'s keys.
324+
/// An iterator over the keys of a `BTreeMap`.
325+
///
326+
/// This `struct` is created by the [`keys`] method on [`BTreeMap`]. See its
327+
/// documentation for more.
328+
///
329+
/// [`keys`]: struct.BTreeMap.html#method.keys
330+
/// [`BTreeMap`]: struct.BTreeMap.html
307331
#[stable(feature = "rust1", since = "1.0.0")]
308332
pub struct Keys<'a, K: 'a, V: 'a> {
309333
inner: Iter<'a, K, V>,
@@ -316,7 +340,13 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Keys<'a, K, V> {
316340
}
317341
}
318342

319-
/// An iterator over a `BTreeMap`'s values.
343+
/// An iterator over the values of a `BTreeMap`.
344+
///
345+
/// This `struct` is created by the [`values`] method on [`BTreeMap`]. See its
346+
/// documentation for more.
347+
///
348+
/// [`values`]: struct.BTreeMap.html#method.values
349+
/// [`BTreeMap`]: struct.BTreeMap.html
320350
#[stable(feature = "rust1", since = "1.0.0")]
321351
pub struct Values<'a, K: 'a, V: 'a> {
322352
inner: Iter<'a, K, V>,
@@ -329,14 +359,26 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Values<'a, K, V>
329359
}
330360
}
331361

332-
/// A mutable iterator over a `BTreeMap`'s values.
362+
/// A mutable iterator over the values of a `BTreeMap`.
363+
///
364+
/// This `struct` is created by the [`values_mut`] method on [`BTreeMap`]. See its
365+
/// documentation for more.
366+
///
367+
/// [`values_mut`]: struct.BTreeMap.html#method.values_mut
368+
/// [`BTreeMap`]: struct.BTreeMap.html
333369
#[stable(feature = "map_values_mut", since = "1.10.0")]
334370
#[derive(Debug)]
335371
pub struct ValuesMut<'a, K: 'a, V: 'a> {
336372
inner: IterMut<'a, K, V>,
337373
}
338374

339-
/// An iterator over a sub-range of `BTreeMap`'s entries.
375+
/// An iterator over a sub-range of entries in a `BTreeMap`.
376+
///
377+
/// This `struct` is created by the [`range`] method on [`BTreeMap`]. See its
378+
/// documentation for more.
379+
///
380+
/// [`range`]: struct.BTreeMap.html#method.range
381+
/// [`BTreeMap`]: struct.BTreeMap.html
340382
#[stable(feature = "btree_range", since = "1.17.0")]
341383
pub struct Range<'a, K: 'a, V: 'a> {
342384
front: Handle<NodeRef<marker::Immut<'a>, K, V, marker::Leaf>, marker::Edge>,
@@ -350,7 +392,13 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for Range<'a, K, V>
350392
}
351393
}
352394

353-
/// A mutable iterator over a sub-range of `BTreeMap`'s entries.
395+
/// A mutable iterator over a sub-range of entries in a `BTreeMap`.
396+
///
397+
/// This `struct` is created by the [`range_mut`] method on [`BTreeMap`]. See its
398+
/// documentation for more.
399+
///
400+
/// [`range_mut`]: struct.BTreeMap.html#method.range_mut
401+
/// [`BTreeMap`]: struct.BTreeMap.html
354402
#[stable(feature = "btree_range", since = "1.17.0")]
355403
pub struct RangeMut<'a, K: 'a, V: 'a> {
356404
front: Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::Edge>,

src/libcollections/btree/set.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ pub struct BTreeSet<T> {
7474
map: BTreeMap<T, ()>,
7575
}
7676

77-
/// An iterator over a `BTreeSet`'s items.
77+
/// An iterator over the items of a `BTreeSet`.
7878
///
79-
/// This structure is created by the [`iter`] method on [`BTreeSet`].
79+
/// This `struct` is created by the [`iter`] method on [`BTreeSet`].
80+
/// See its documentation for more.
8081
///
8182
/// [`BTreeSet`]: struct.BTreeSet.html
8283
/// [`iter`]: struct.BTreeSet.html#method.iter
@@ -94,21 +95,23 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for Iter<'a, T> {
9495
}
9596
}
9697

97-
/// An owning iterator over a `BTreeSet`'s items.
98+
/// An owning iterator over the items of a `BTreeSet`.
9899
///
99-
/// This structure is created by the `into_iter` method on [`BTreeSet`]
100-
/// [`BTreeSet`] (provided by the `IntoIterator` trait).
100+
/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`]
101+
/// (provided by the `IntoIterator` trait). See its documentation for more.
101102
///
102103
/// [`BTreeSet`]: struct.BTreeSet.html
104+
/// [`into_iter`]: struct.BTreeSet.html#method.into_iter
103105
#[stable(feature = "rust1", since = "1.0.0")]
104106
#[derive(Debug)]
105107
pub struct IntoIter<T> {
106108
iter: ::btree_map::IntoIter<T, ()>,
107109
}
108110

109-
/// An iterator over a sub-range of `BTreeSet`'s items.
111+
/// An iterator over a sub-range of items in a `BTreeSet`.
110112
///
111-
/// This structure is created by the [`range`] method on [`BTreeSet`].
113+
/// This `struct` is created by the [`range`] method on [`BTreeSet`].
114+
/// See its documentation for more.
112115
///
113116
/// [`BTreeSet`]: struct.BTreeSet.html
114117
/// [`range`]: struct.BTreeSet.html#method.range
@@ -118,9 +121,10 @@ pub struct Range<'a, T: 'a> {
118121
iter: ::btree_map::Range<'a, T, ()>,
119122
}
120123

121-
/// A lazy iterator producing elements in the set difference (in-order).
124+
/// A lazy iterator producing elements in the difference of `BTreeSet`s.
122125
///
123-
/// This structure is created by the [`difference`] method on [`BTreeSet`].
126+
/// This `struct` is created by the [`difference`] method on [`BTreeSet`].
127+
/// See its documentation for more.
124128
///
125129
/// [`BTreeSet`]: struct.BTreeSet.html
126130
/// [`difference`]: struct.BTreeSet.html#method.difference
@@ -139,10 +143,10 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for Difference<'a, T> {
139143
}
140144
}
141145

142-
/// A lazy iterator producing elements in the set symmetric difference (in-order).
146+
/// A lazy iterator producing elements in the symmetric difference of `BTreeSet`s.
143147
///
144-
/// This structure is created by the [`symmetric_difference`] method on
145-
/// [`BTreeSet`].
148+
/// This `struct` is created by the [`symmetric_difference`] method on
149+
/// [`BTreeSet`]. See its documentation for more.
146150
///
147151
/// [`BTreeSet`]: struct.BTreeSet.html
148152
/// [`symmetric_difference`]: struct.BTreeSet.html#method.symmetric_difference
@@ -161,9 +165,10 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for SymmetricDifference<'a, T> {
161165
}
162166
}
163167

164-
/// A lazy iterator producing elements in the set intersection (in-order).
168+
/// A lazy iterator producing elements in the intersection of `BTreeSet`s.
165169
///
166-
/// This structure is created by the [`intersection`] method on [`BTreeSet`].
170+
/// This `struct` is created by the [`intersection`] method on [`BTreeSet`].
171+
/// See its documentation for more.
167172
///
168173
/// [`BTreeSet`]: struct.BTreeSet.html
169174
/// [`intersection`]: struct.BTreeSet.html#method.intersection
@@ -182,9 +187,10 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for Intersection<'a, T> {
182187
}
183188
}
184189

185-
/// A lazy iterator producing elements in the set union (in-order).
190+
/// A lazy iterator producing elements in the union of `BTreeSet`s.
186191
///
187-
/// This structure is created by the [`union`] method on [`BTreeSet`].
192+
/// This `struct` is created by the [`union`] method on [`BTreeSet`].
193+
/// See its documentation for more.
188194
///
189195
/// [`BTreeSet`]: struct.BTreeSet.html
190196
/// [`union`]: struct.BTreeSet.html#method.union

src/libcollections/linked_list.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ struct Node<T> {
5656
element: T,
5757
}
5858

59-
/// An iterator over references to the elements of a `LinkedList`.
59+
/// An iterator over the elements of a `LinkedList`.
60+
///
61+
/// This `struct` is created by the [`iter`] method on [`LinkedList`]. See its
62+
/// documentation for more.
63+
///
64+
/// [`iter`]: struct.LinkedList.html#method.iter
65+
/// [`LinkedList`]: struct.LinkedList.html
6066
#[stable(feature = "rust1", since = "1.0.0")]
6167
pub struct Iter<'a, T: 'a> {
6268
head: Option<Shared<Node<T>>>,
@@ -82,7 +88,13 @@ impl<'a, T> Clone for Iter<'a, T> {
8288
}
8389
}
8490

85-
/// An iterator over mutable references to the elements of a `LinkedList`.
91+
/// A mutable iterator over the elements of a `LinkedList`.
92+
///
93+
/// This `struct` is created by the [`iter_mut`] method on [`LinkedList`]. See its
94+
/// documentation for more.
95+
///
96+
/// [`iter_mut`]: struct.LinkedList.html#method.iter_mut
97+
/// [`LinkedList`]: struct.LinkedList.html
8698
#[stable(feature = "rust1", since = "1.0.0")]
8799
pub struct IterMut<'a, T: 'a> {
88100
list: &'a mut LinkedList<T>,
@@ -100,7 +112,13 @@ impl<'a, T: 'a + fmt::Debug> fmt::Debug for IterMut<'a, T> {
100112
}
101113
}
102114

103-
/// An iterator over the elements of a `LinkedList`.
115+
/// An owning iterator over the elements of a `LinkedList`.
116+
///
117+
/// This `struct` is created by the [`into_iter`] method on [`LinkedList`]
118+
/// (provided by the `IntoIterator` trait). See its documentation for more.
119+
///
120+
/// [`into_iter`]: struct.LinkedList.html#method.into_iter
121+
/// [`LinkedList`]: struct.LinkedList.html
104122
#[derive(Clone)]
105123
#[stable(feature = "rust1", since = "1.0.0")]
106124
pub struct IntoIter<T> {

src/libcollections/vec_deque.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,13 @@ fn count(tail: usize, head: usize, size: usize) -> usize {
18901890
(head.wrapping_sub(tail)) & (size - 1)
18911891
}
18921892

1893-
/// `VecDeque` iterator.
1893+
/// An iterator over the elements of a `VecDeque`.
1894+
///
1895+
/// This `struct` is created by the [`iter`] method on [`VecDeque`]. See its
1896+
/// documentation for more.
1897+
///
1898+
/// [`iter`]: struct.VecDeque.html#method.iter
1899+
/// [`VecDeque`]: struct.VecDeque.html
18941900
#[stable(feature = "rust1", since = "1.0.0")]
18951901
pub struct Iter<'a, T: 'a> {
18961902
ring: &'a [T],
@@ -1971,7 +1977,13 @@ impl<'a, T> ExactSizeIterator for Iter<'a, T> {
19711977
impl<'a, T> FusedIterator for Iter<'a, T> {}
19721978

19731979

1974-
/// `VecDeque` mutable iterator.
1980+
/// A mutable iterator over the elements of a `VecDeque`.
1981+
///
1982+
/// This `struct` is created by the [`iter_mut`] method on [`VecDeque`]. See its
1983+
/// documentation for more.
1984+
///
1985+
/// [`iter_mut`]: struct.VecDeque.html#method.iter_mut
1986+
/// [`VecDeque`]: struct.VecDeque.html
19751987
#[stable(feature = "rust1", since = "1.0.0")]
19761988
pub struct IterMut<'a, T: 'a> {
19771989
ring: &'a mut [T],
@@ -2047,7 +2059,13 @@ impl<'a, T> ExactSizeIterator for IterMut<'a, T> {
20472059
#[unstable(feature = "fused", issue = "35602")]
20482060
impl<'a, T> FusedIterator for IterMut<'a, T> {}
20492061

2050-
/// A by-value `VecDeque` iterator
2062+
/// An owning iterator over the elements of a `VecDeque`.
2063+
///
2064+
/// This `struct` is created by the [`into_iter`] method on [`VecDeque`]
2065+
/// (provided by the `IntoIterator` trait). See its documentation for more.
2066+
///
2067+
/// [`into_iter`]: struct.VecDeque.html#method.into_iter
2068+
/// [`VecDeque`]: struct.VecDeque.html
20512069
#[derive(Clone)]
20522070
#[stable(feature = "rust1", since = "1.0.0")]
20532071
pub struct IntoIter<T> {
@@ -2097,7 +2115,13 @@ impl<T> ExactSizeIterator for IntoIter<T> {
20972115
#[unstable(feature = "fused", issue = "35602")]
20982116
impl<T> FusedIterator for IntoIter<T> {}
20992117

2100-
/// A draining `VecDeque` iterator
2118+
/// A draining iterator over the elements of a `VecDeque`.
2119+
///
2120+
/// This `struct` is created by the [`drain`] method on [`VecDeque`]. See its
2121+
/// documentation for more.
2122+
///
2123+
/// [`drain`]: struct.VecDeque.html#method.drain
2124+
/// [`VecDeque`]: struct.VecDeque.html
21012125
#[stable(feature = "drain", since = "1.6.0")]
21022126
pub struct Drain<'a, T: 'a> {
21032127
after_tail: usize,

0 commit comments

Comments
 (0)