Skip to content

Commit d688c4d

Browse files
author
lukaramu
committed
Various fixes throughout std::collections' docs
* Added links where possible (limited because of facading) * Changed references to methods from `foo()` to `foo` in module docs * Changed references to methods from `HashMap::foo` to just `foo` in top-level docs for `HashMap` and the `default` doc for `DefaultHasher` * Various small other fixes
1 parent d64de94 commit d688c4d

File tree

7 files changed

+106
-74
lines changed

7 files changed

+106
-74
lines changed

src/libcollections/binary_heap.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
//!
2121
//! This is a larger example that implements [Dijkstra's algorithm][dijkstra]
2222
//! to solve the [shortest path problem][sssp] on a [directed graph][dir_graph].
23-
//! It shows how to use `BinaryHeap` with custom types.
23+
//! It shows how to use [`BinaryHeap`] with custom types.
2424
//!
2525
//! [dijkstra]: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
2626
//! [sssp]: http://en.wikipedia.org/wiki/Shortest_path_problem
2727
//! [dir_graph]: http://en.wikipedia.org/wiki/Directed_graph
28+
//! [`BinaryHeap`]: struct.BinaryHeap.html
2829
//!
2930
//! ```
3031
//! use std::cmp::Ordering;
@@ -438,7 +439,7 @@ impl<T: Ord> BinaryHeap<T> {
438439
/// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
439440
///
440441
/// Note that the allocator may give the collection more space than it requests. Therefore
441-
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future
442+
/// capacity can not be relied upon to be precisely minimal. Prefer [`reserve`] if future
442443
/// insertions are expected.
443444
///
444445
/// # Panics
@@ -456,6 +457,8 @@ impl<T: Ord> BinaryHeap<T> {
456457
/// assert!(heap.capacity() >= 100);
457458
/// heap.push(4);
458459
/// ```
460+
///
461+
/// [`reserve`]: #method.reserve
459462
#[stable(feature = "rust1", since = "1.0.0")]
460463
pub fn reserve_exact(&mut self, additional: usize) {
461464
self.data.reserve_exact(additional);

src/libcollections/btree/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ impl<T> IntoIterator for BTreeSet<T> {
734734
type Item = T;
735735
type IntoIter = IntoIter<T>;
736736

737-
/// Gets an iterator for moving out the BtreeSet's contents.
737+
/// Gets an iterator for moving out the `BTreeSet`'s contents.
738738
///
739739
/// # Examples
740740
///

src/libcollections/linked_list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,12 @@ impl<T> LinkedList<T> {
636636
/// Splits the list into two at the given index. Returns everything after the given index,
637637
/// including the index.
638638
///
639+
/// This operation should compute in O(n) time.
640+
///
639641
/// # Panics
640642
///
641643
/// Panics if `at > len`.
642644
///
643-
/// This operation should compute in O(n) time.
644-
///
645645
/// # Examples
646646
///
647647
/// ```

src/libcollections/vec_deque.rs

Lines changed: 10 additions & 3 deletions
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
@@ -506,7 +511,7 @@ 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
@@ -522,6 +527,8 @@ impl<T> VecDeque<T> {
522527
/// buf.reserve_exact(10);
523528
/// assert!(buf.capacity() >= 11);
524529
/// ```
530+
///
531+
/// [`reserve`]: #method.reserve
525532
#[stable(feature = "rust1", since = "1.0.0")]
526533
pub fn reserve_exact(&mut self, additional: usize) {
527534
self.reserve(additional);

src/libstd/collections/hash/map.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,8 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
235235
/// attacks such as HashDoS.
236236
///
237237
/// The hashing algorithm can be replaced on a per-`HashMap` basis using the
238-
/// [`HashMap::default`], [`HashMap::with_hasher`], and
239-
/// [`HashMap::with_capacity_and_hasher`] methods. Many alternative algorithms
240-
/// are available on crates.io, such as the [`fnv`] crate.
238+
/// [`default`], [`with_hasher`], and [`with_capacity_and_hasher`] methods. Many
239+
/// alternative algorithms are available on crates.io, such as the [`fnv`] crate.
241240
///
242241
/// It is required that the keys implement the [`Eq`] and [`Hash`] traits, although
243242
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
@@ -339,9 +338,9 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
339338
/// [`PartialEq`]: ../../std/cmp/trait.PartialEq.html
340339
/// [`RefCell`]: ../../std/cell/struct.RefCell.html
341340
/// [`Cell`]: ../../std/cell/struct.Cell.html
342-
/// [`HashMap::default`]: #method.default
343-
/// [`HashMap::with_hasher`]: #method.with_hasher
344-
/// [`HashMap::with_capacity_and_hasher`]: #method.with_capacity_and_hasher
341+
/// [`default`]: #method.default
342+
/// [`with_hasher`]: #method.with_hasher
343+
/// [`with_capacity_and_hasher`]: #method.with_capacity_and_hasher
345344
/// [`fnv`]: https://crates.io/crates/fnv
346345
///
347346
/// ```
@@ -373,7 +372,7 @@ const DISPLACEMENT_THRESHOLD: usize = 128;
373372
/// }
374373
/// ```
375374
///
376-
/// A HashMap with fixed list of elements can be initialized from an array:
375+
/// A `HashMap` with fixed list of elements can be initialized from an array:
377376
///
378377
/// ```
379378
/// use std::collections::HashMap;
@@ -654,12 +653,13 @@ impl<K, V, S> HashMap<K, V, S>
654653
}
655654
}
656655

657-
/// Creates an empty `HashMap` with the specified capacity, using `hasher`
656+
/// Creates an empty `HashMap` with the specified capacity, using `hash_builder`
658657
/// to hash the keys.
659658
///
660659
/// The hash map will be able to hold at least `capacity` elements without
661660
/// reallocating. If `capacity` is 0, the hash map will not allocate.
662-
/// Warning: `hasher` is normally randomly generated, and
661+
///
662+
/// Warning: `hash_builder` is normally randomly generated, and
663663
/// is designed to allow HashMaps to be resistant to attacks that
664664
/// cause many collisions and very poor performance. Setting it
665665
/// manually using this function can expose a DoS attack vector.
@@ -686,7 +686,9 @@ impl<K, V, S> HashMap<K, V, S>
686686
}
687687
}
688688

689-
/// Returns a reference to the map's hasher.
689+
/// Returns a reference to the map's [`BuildHasher`].
690+
///
691+
/// [`BuildHasher`]: ../../std/hash/trait.BuildHasher.html
690692
#[stable(feature = "hashmap_public_hasher", since = "1.9.0")]
691693
pub fn hasher(&self) -> &S {
692694
&self.hash_builder
@@ -849,7 +851,7 @@ impl<K, V, S> HashMap<K, V, S>
849851
}
850852

851853
/// An iterator visiting all keys in arbitrary order.
852-
/// Iterator element type is `&'a K`.
854+
/// The iterator element type is `&'a K`.
853855
///
854856
/// # Examples
855857
///
@@ -871,7 +873,7 @@ impl<K, V, S> HashMap<K, V, S>
871873
}
872874

873875
/// An iterator visiting all values in arbitrary order.
874-
/// Iterator element type is `&'a V`.
876+
/// The iterator element type is `&'a V`.
875877
///
876878
/// # Examples
877879
///
@@ -893,7 +895,7 @@ impl<K, V, S> HashMap<K, V, S>
893895
}
894896

895897
/// An iterator visiting all values mutably in arbitrary order.
896-
/// Iterator element type is `&'a mut V`.
898+
/// The iterator element type is `&'a mut V`.
897899
///
898900
/// # Examples
899901
///
@@ -920,7 +922,7 @@ impl<K, V, S> HashMap<K, V, S>
920922
}
921923

922924
/// An iterator visiting all key-value pairs in arbitrary order.
923-
/// Iterator element type is `(&'a K, &'a V)`.
925+
/// The iterator element type is `(&'a K, &'a V)`.
924926
///
925927
/// # Examples
926928
///
@@ -943,7 +945,7 @@ impl<K, V, S> HashMap<K, V, S>
943945

944946
/// An iterator visiting all key-value pairs in arbitrary order,
945947
/// with mutable references to the values.
946-
/// Iterator element type is `(&'a K, &'a mut V)`.
948+
/// The iterator element type is `(&'a K, &'a mut V)`.
947949
///
948950
/// # Examples
949951
///
@@ -2408,10 +2410,9 @@ impl DefaultHasher {
24082410

24092411
#[stable(feature = "hashmap_default_hasher", since = "1.13.0")]
24102412
impl Default for DefaultHasher {
2411-
/// Creates a new `DefaultHasher` using [`DefaultHasher::new`]. See
2412-
/// [`DefaultHasher::new`] documentation for more information.
2413+
/// Creates a new `DefaultHasher` using [`new`]. See its documentation for more.
24132414
///
2414-
/// [`DefaultHasher::new`]: #method.new
2415+
/// [`new`]: #method.new
24152416
fn default() -> DefaultHasher {
24162417
DefaultHasher::new()
24172418
}

0 commit comments

Comments
 (0)