Skip to content

Commit 89ac865

Browse files
author
lukaramu
committed
Various consistency and phrasing fixes in std::collections' docs
* Changed btree_map's and hash_map's Entry (etc.) docs to be consistent * Changed VecDeque's type and module summary sentences to be consistent with each other as well as with other summary sentences in the module * Changed HashMap's and HashSet's summary sentences to be less redundantly phrased and also more consistant with the other summary sentences in the module * Also, added an example to Bound
1 parent d688c4d commit 89ac865

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

src/libcollections/btree/map.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,18 +420,19 @@ impl<'a, K: 'a + fmt::Debug, V: 'a + fmt::Debug> fmt::Debug for RangeMut<'a, K,
420420
}
421421

422422
/// A view into a single entry in a map, which may either be vacant or occupied.
423-
/// This enum is constructed from the [`entry`] method on [`BTreeMap`].
423+
///
424+
/// This `enum` is constructed from the [`entry`] method on [`BTreeMap`].
424425
///
425426
/// [`BTreeMap`]: struct.BTreeMap.html
426427
/// [`entry`]: struct.BTreeMap.html#method.entry
427428
#[stable(feature = "rust1", since = "1.0.0")]
428429
pub enum Entry<'a, K: 'a, V: 'a> {
429-
/// A vacant `Entry`
430+
/// A vacant entry.
430431
#[stable(feature = "rust1", since = "1.0.0")]
431432
Vacant(#[stable(feature = "rust1", since = "1.0.0")]
432433
VacantEntry<'a, K, V>),
433434

434-
/// An occupied `Entry`
435+
/// An occupied entry.
435436
#[stable(feature = "rust1", since = "1.0.0")]
436437
Occupied(#[stable(feature = "rust1", since = "1.0.0")]
437438
OccupiedEntry<'a, K, V>),
@@ -451,7 +452,8 @@ impl<'a, K: 'a + Debug + Ord, V: 'a + Debug> Debug for Entry<'a, K, V> {
451452
}
452453
}
453454

454-
/// A vacant `Entry`. It is part of the [`Entry`] enum.
455+
/// A view into a vacant entry in a `BTreeMap`.
456+
/// It is part of the [`Entry`] enum.
455457
///
456458
/// [`Entry`]: enum.Entry.html
457459
#[stable(feature = "rust1", since = "1.0.0")]
@@ -473,7 +475,8 @@ impl<'a, K: 'a + Debug + Ord, V: 'a> Debug for VacantEntry<'a, K, V> {
473475
}
474476
}
475477

476-
/// An occupied `Entry`. It is part of the [`Entry`] enum.
478+
/// A view into an occupied entry in a `BTreeMap`.
479+
/// It is part of the [`Entry`] enum.
477480
///
478481
/// [`Entry`]: enum.Entry.html
479482
#[stable(feature = "rust1", since = "1.0.0")]

src/libcollections/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ mod std {
135135
}
136136

137137
/// An endpoint of a range of keys.
138+
/// # Examples
139+
///
140+
/// ```
141+
/// use std::collections::BTreeMap;
142+
/// use std::collections::Bound::{Excluded, Included, Unbounded};
143+
///
144+
/// let mut map = BTreeMap::new();
145+
/// map.insert(3, "a");
146+
/// map.insert(5, "b");
147+
/// map.insert(8, "c");
148+
///
149+
/// for (key, value) in map.range((Excluded(3), Included(8))) {
150+
/// println!("{}: {}", key, value);
151+
/// }
152+
///
153+
/// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
154+
/// ```
138155
#[stable(feature = "collections_bound", since = "1.17.0")]
139156
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
140157
pub enum Bound<T> {

src/libcollections/vec_deque.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! `VecDeque` is a double-ended queue, which is implemented with the help of a
12-
//! growing ring buffer.
11+
//! A double-ended queue implemented with a growable ring buffer.
1312
//!
1413
//! This queue has `O(1)` amortized inserts and removals from both ends of the
1514
//! container. It also has `O(1)` indexing like a vector. The contained elements
@@ -43,8 +42,7 @@ const MAXIMUM_ZST_CAPACITY: usize = 1 << (32 - 1); // Largest possible power of
4342
#[cfg(target_pointer_width = "64")]
4443
const MAXIMUM_ZST_CAPACITY: usize = 1 << (64 - 1); // Largest possible power of two
4544

46-
/// `VecDeque` is a growable ring buffer, which can be used as a double-ended
47-
/// queue efficiently.
45+
/// A double-ended queue implemented with a growable ring buffer.
4846
///
4947
/// The "default" usage of this type as a queue is to use [`push_back`] to add to
5048
/// the queue, and [`pop_front`] to remove from the queue. [`extend`] and [`append`]

src/libstd/collections/hash/map.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
215215
// 1. Alfredo Viola (2005). Distributional analysis of Robin Hood linear probing
216216
// hashing with buckets.
217217

218-
/// A hash map implementation which uses linear probing with Robin Hood bucket
219-
/// stealing.
218+
/// A hash map implemented with linear probing and Robin Hood bucket stealing.
220219
///
221220
/// By default, `HashMap` uses a hashing algorithm selected to provide
222221
/// resistance against HashDoS attacks. The algorithm is randomly seeded, and a
@@ -1511,19 +1510,20 @@ impl<'a, K, V> InternalEntry<K, V, &'a mut RawTable<K, V>> {
15111510
}
15121511
}
15131512

1514-
/// A view into a single location in a map, which may be vacant or occupied.
1515-
/// This enum is constructed from the [`entry`] method on [`HashMap`].
1513+
/// A view into a single entry in a map, which may either be vacant or occupied.
1514+
///
1515+
/// This `enum` is constructed from the [`entry`] method on [`HashMap`].
15161516
///
15171517
/// [`HashMap`]: struct.HashMap.html
15181518
/// [`entry`]: struct.HashMap.html#method.entry
15191519
#[stable(feature = "rust1", since = "1.0.0")]
15201520
pub enum Entry<'a, K: 'a, V: 'a> {
1521-
/// An occupied Entry.
1521+
/// An occupied entry.
15221522
#[stable(feature = "rust1", since = "1.0.0")]
15231523
Occupied(#[stable(feature = "rust1", since = "1.0.0")]
15241524
OccupiedEntry<'a, K, V>),
15251525

1526-
/// A vacant Entry.
1526+
/// A vacant entry.
15271527
#[stable(feature = "rust1", since = "1.0.0")]
15281528
Vacant(#[stable(feature = "rust1", since = "1.0.0")]
15291529
VacantEntry<'a, K, V>),
@@ -1547,7 +1547,7 @@ impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for Entry<'a, K, V> {
15471547
}
15481548
}
15491549

1550-
/// A view into a single occupied location in a HashMap.
1550+
/// A view into an occupied entry in a `HashMap`.
15511551
/// It is part of the [`Entry`] enum.
15521552
///
15531553
/// [`Entry`]: enum.Entry.html
@@ -1567,7 +1567,7 @@ impl<'a, K: 'a + Debug, V: 'a + Debug> Debug for OccupiedEntry<'a, K, V> {
15671567
}
15681568
}
15691569

1570-
/// A view into a single empty location in a HashMap.
1570+
/// A view into a vacant entry in a `HashMap`.
15711571
/// It is part of the [`Entry`] enum.
15721572
///
15731573
/// [`Entry`]: enum.Entry.html

src/libstd/collections/hash/set.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use super::map::{self, HashMap, Keys, RandomState};
2424
// for `bucket.val` in the case of HashSet. I suppose we would need HKT
2525
// to get rid of it properly.
2626

27-
/// An implementation of a hash set using the underlying representation of a
28-
/// `HashMap` where the value is ().
27+
/// A hash set implemented as a `HashMap` where the value is `()`.
2928
///
3029
/// As with the [`HashMap`] type, a `HashSet` requires that the elements
3130
/// implement the [`Eq`] and [`Hash`] traits. This can frequently be achieved by

src/libstd/collections/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,14 @@ mod hash;
442442

443443
#[stable(feature = "rust1", since = "1.0.0")]
444444
pub mod hash_map {
445-
//! A hash map implementation which uses linear probing with Robin
446-
//! Hood bucket stealing.
445+
//! A hash map implemented with linear probing and Robin Hood bucket stealing.
447446
#[stable(feature = "rust1", since = "1.0.0")]
448447
pub use super::hash::map::*;
449448
}
450449

451450
#[stable(feature = "rust1", since = "1.0.0")]
452451
pub mod hash_set {
453-
//! An implementation of a hash set using the underlying representation of a
454-
//! `HashMap` where the value is ().
452+
//! A hash set implemented as a `HashMap` where the value is `()`.
455453
#[stable(feature = "rust1", since = "1.0.0")]
456454
pub use super::hash::set::*;
457455
}

0 commit comments

Comments
 (0)