Skip to content

Commit

Permalink
Merge pull request #295 from cuviper/doc-links
Browse files Browse the repository at this point in the history
Use more rustdoc auto-links
  • Loading branch information
cuviper authored Jan 15, 2024
2 parents cd74680 + 1e873cc commit 5c7e734
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 261 deletions.
16 changes: 4 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
//! [`IndexSet`] is a corresponding hash set using the same implementation and
//! with similar properties.
//!
//! [`IndexMap`]: map/struct.IndexMap.html
//! [`IndexSet`]: set/struct.IndexSet.html
//!
//!
//! ### Highlights
//!
//! [`IndexMap`] and [`IndexSet`] are drop-in compatible with the std `HashMap`
Expand Down Expand Up @@ -55,7 +51,8 @@
//!
//! ### Alternate Hashers
//!
//! [`IndexMap`] and [`IndexSet`] have a default hasher type `S = RandomState`,
//! [`IndexMap`] and [`IndexSet`] have a default hasher type
//! [`S = RandomState`][std::collections::hash_map::RandomState],
//! just like the standard `HashMap` and `HashSet`, which is resistant to
//! HashDoS attacks but not the most performant. Type aliases can make it easier
//! to use alternate hashers:
Expand Down Expand Up @@ -94,14 +91,11 @@
//!
//! - Creating maps and sets using [`new`][IndexMap::new] and
//! [`with_capacity`][IndexMap::with_capacity] is unavailable without `std`.
//! Use methods [`IndexMap::default`][def],
//! [`with_hasher`][IndexMap::with_hasher],
//! Use methods [`IndexMap::default`], [`with_hasher`][IndexMap::with_hasher],
//! [`with_capacity_and_hasher`][IndexMap::with_capacity_and_hasher] instead.
//! A no-std compatible hasher will be needed as well, for example
//! from the crate `twox-hash`.
//! - Macros [`indexmap!`] and [`indexset!`] are unavailable without `std`.
//!
//! [def]: map/struct.IndexMap.html#impl-Default
#![cfg_attr(docsrs, feature(doc_cfg))]

Expand All @@ -118,7 +112,6 @@ mod arbitrary;
mod macros;
mod mutable_keys;
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
mod serde;
mod util;

Expand All @@ -128,7 +121,6 @@ pub mod set;
// Placed after `map` and `set` so new `rayon` methods on the types
// are documented after the "normal" methods.
#[cfg(feature = "rayon")]
#[cfg_attr(docsrs, doc(cfg(feature = "rayon")))]
mod rayon;

#[cfg(feature = "rustc-rayon")]
Expand Down Expand Up @@ -220,7 +212,7 @@ trait Entries {
F: FnOnce(&mut [Self::Entry]);
}

/// The error type for `try_reserve` methods.
/// The error type for [`try_reserve`][IndexMap::try_reserve] methods.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct TryReserveError {
kind: TryReserveErrorKind,
Expand Down
4 changes: 2 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[macro_export]
/// Create an `IndexMap` from a list of key-value pairs
/// Create an [`IndexMap`][crate::IndexMap] from a list of key-value pairs
///
/// ## Example
///
Expand Down Expand Up @@ -38,7 +38,7 @@ macro_rules! indexmap {
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
#[macro_export]
/// Create an `IndexSet` from a list of values
/// Create an [`IndexSet`][crate::IndexSet] from a list of values
///
/// ## Example
///
Expand Down
56 changes: 29 additions & 27 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `IndexMap` is a hash table where the iteration order of the key-value
//! [`IndexMap`] is a hash table where the iteration order of the key-value
//! pairs is independent of the hash values of the keys.
mod core;
Expand All @@ -12,7 +12,7 @@ pub mod serde_seq;
#[cfg(test)]
mod tests;

pub use self::core::{Entry, OccupiedEntry, VacantEntry};
pub use self::core::{Entry, IndexedEntry, OccupiedEntry, VacantEntry};
pub use self::iter::{
Drain, IntoIter, IntoKeys, IntoValues, Iter, IterMut, Keys, Values, ValuesMut,
};
Expand All @@ -32,15 +32,16 @@ use alloc::vec::Vec;
#[cfg(feature = "std")]
use std::collections::hash_map::RandomState;

use self::core::{IndexMapCore, IndexedEntry};
use self::core::IndexMapCore;
use crate::util::{third, try_simplify_range};
use crate::{Bucket, Entries, Equivalent, HashValue, TryReserveError};

/// A hash table where the iteration order of the key-value pairs is independent
/// of the hash values of the keys.
///
/// The interface is closely compatible with the standard `HashMap`, but also
/// has additional features.
/// The interface is closely compatible with the standard
/// [`HashMap`][std::collections::HashMap],
/// but also has additional features.
///
/// # Order
///
Expand All @@ -51,7 +52,8 @@ use crate::{Bucket, Entries, Equivalent, HashValue, TryReserveError};
/// All iterators traverse the map in *the order*.
///
/// The insertion order is preserved, with **notable exceptions** like the
/// `.remove()` or `.swap_remove()` methods. Methods such as `.sort_by()` of
/// [`.remove()`][Self::remove] or [`.swap_remove()`][Self::swap_remove] methods.
/// Methods such as [`.sort_by()`][Self::sort_by] of
/// course result in a new order, depending on the sorting order.
///
/// # Indices
Expand Down Expand Up @@ -281,7 +283,7 @@ impl<K, V, S> IndexMap<K, V, S> {
/// Clears the `IndexMap` in the given index range, returning those
/// key-value pairs as a drain iterator.
///
/// The range may be any type that implements `RangeBounds<usize>`,
/// The range may be any type that implements [`RangeBounds<usize>`],
/// including all of the `std::ops::Range*` types, or even a tuple pair of
/// `Bound` start and end values. To drain the map entirely, use `RangeFull`
/// like `map.drain(..)`.
Expand Down Expand Up @@ -390,8 +392,9 @@ where
///
/// Computes in **O(1)** time (amortized average).
///
/// See also [`entry`](#method.entry) if you you want to insert *or* modify
/// or if you need to get the index of the corresponding key-value pair.
/// See also [`entry`][Self::entry] if you you want to insert *or* modify,
/// or [`insert_full`][Self::insert_full] if you need to get the index of
/// the corresponding key-value pair.
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
self.insert_full(key, value).1
}
Expand All @@ -407,8 +410,7 @@ where
///
/// Computes in **O(1)** time (amortized average).
///
/// See also [`entry`](#method.entry) if you you want to insert *or* modify
/// or if you need to get the index of the corresponding key-value pair.
/// See also [`entry`][Self::entry] if you you want to insert *or* modify.
pub fn insert_full(&mut self, key: K, value: V) -> (usize, Option<V>) {
let hash = self.hash(&key);
self.core.insert_full(hash, key, value)
Expand Down Expand Up @@ -551,7 +553,7 @@ where
/// Remove the key-value pair equivalent to `key` and return
/// its value.
///
/// Like `Vec::swap_remove`, the pair is removed by swapping it with the
/// Like [`Vec::swap_remove`], the pair is removed by swapping it with the
/// last element of the map and popping it off. **This perturbs
/// the position of what used to be the last element!**
///
Expand All @@ -567,7 +569,7 @@ where

/// Remove and return the key-value pair equivalent to `key`.
///
/// Like `Vec::swap_remove`, the pair is removed by swapping it with the
/// Like [`Vec::swap_remove`], the pair is removed by swapping it with the
/// last element of the map and popping it off. **This perturbs
/// the position of what used to be the last element!**
///
Expand All @@ -587,7 +589,7 @@ where
/// Remove the key-value pair equivalent to `key` and return it and
/// the index it had.
///
/// Like `Vec::swap_remove`, the pair is removed by swapping it with the
/// Like [`Vec::swap_remove`], the pair is removed by swapping it with the
/// last element of the map and popping it off. **This perturbs
/// the position of what used to be the last element!**
///
Expand All @@ -608,7 +610,7 @@ where
/// Remove the key-value pair equivalent to `key` and return
/// its value.
///
/// Like `Vec::remove`, the pair is removed by shifting all of the
/// Like [`Vec::remove`], the pair is removed by shifting all of the
/// elements that follow it, preserving their relative order.
/// **This perturbs the index of all of those elements!**
///
Expand All @@ -624,7 +626,7 @@ where

/// Remove and return the key-value pair equivalent to `key`.
///
/// Like `Vec::remove`, the pair is removed by shifting all of the
/// Like [`Vec::remove`], the pair is removed by shifting all of the
/// elements that follow it, preserving their relative order.
/// **This perturbs the index of all of those elements!**
///
Expand All @@ -644,7 +646,7 @@ where
/// Remove the key-value pair equivalent to `key` and return it and
/// the index it had.
///
/// Like `Vec::remove`, the pair is removed by shifting all of the
/// Like [`Vec::remove`], the pair is removed by shifting all of the
/// elements that follow it, preserving their relative order.
/// **This perturbs the index of all of those elements!**
///
Expand Down Expand Up @@ -967,7 +969,7 @@ impl<K, V, S> IndexMap<K, V, S> {
///
/// Valid indices are *0 <= index < self.len()*
///
/// Like `Vec::swap_remove`, the pair is removed by swapping it with the
/// Like [`Vec::swap_remove`], the pair is removed by swapping it with the
/// last element of the map and popping it off. **This perturbs
/// the position of what used to be the last element!**
///
Expand All @@ -980,7 +982,7 @@ impl<K, V, S> IndexMap<K, V, S> {
///
/// Valid indices are *0 <= index < self.len()*
///
/// Like `Vec::remove`, the pair is removed by shifting all of the
/// Like [`Vec::remove`], the pair is removed by shifting all of the
/// elements that follow it, preserving their relative order.
/// **This perturbs the index of all of those elements!**
///
Expand Down Expand Up @@ -1010,7 +1012,7 @@ impl<K, V, S> IndexMap<K, V, S> {
}
}

/// Access `IndexMap` values corresponding to a key.
/// Access [`IndexMap`] values corresponding to a key.
///
/// # Examples
///
Expand Down Expand Up @@ -1048,7 +1050,7 @@ where
}
}

/// Access `IndexMap` values corresponding to a key.
/// Access [`IndexMap`] values corresponding to a key.
///
/// Mutable indexing allows changing / updating values of key-value
/// pairs that are already present.
Expand Down Expand Up @@ -1091,7 +1093,7 @@ where
}
}

/// Access `IndexMap` values at indexed positions.
/// Access [`IndexMap`] values at indexed positions.
///
/// See [`Index<usize> for Keys`][keys] to access a map's keys instead.
///
Expand Down Expand Up @@ -1136,12 +1138,12 @@ impl<K, V, S> Index<usize> for IndexMap<K, V, S> {
}
}

/// Access `IndexMap` values at indexed positions.
/// Access [`IndexMap`] values at indexed positions.
///
/// Mutable indexing allows changing / updating indexed values
/// that are already present.
///
/// You can **not** insert new values with index syntax, use `.insert()`.
/// You can **not** insert new values with index syntax -- use [`.insert()`][IndexMap::insert].
///
/// # Examples
///
Expand Down Expand Up @@ -1185,7 +1187,7 @@ where
/// iterable.
///
/// `from_iter` uses the same logic as `extend`. See
/// [`extend`](#method.extend) for more details.
/// [`extend`][IndexMap::extend] for more details.
fn from_iter<I: IntoIterator<Item = (K, V)>>(iterable: I) -> Self {
let iter = iterable.into_iter();
let (low, _) = iter.size_hint();
Expand Down Expand Up @@ -1222,7 +1224,7 @@ where
{
/// Extend the map with all key-value pairs in the iterable.
///
/// This is equivalent to calling [`insert`](#method.insert) for each of
/// This is equivalent to calling [`insert`][IndexMap::insert] for each of
/// them in order, which means that for keys that already existed
/// in the map, their value is updated but it keeps the existing order.
///
Expand Down Expand Up @@ -1266,7 +1268,7 @@ impl<K, V, S> Default for IndexMap<K, V, S>
where
S: Default,
{
/// Return an empty `IndexMap`
/// Return an empty [`IndexMap`]
fn default() -> Self {
Self::with_capacity_and_hasher(0, S::default())
}
Expand Down
Loading

0 comments on commit 5c7e734

Please sign in to comment.