Improve formatting of hash collections docs

This commit is contained in:
Camelid 2020-10-26 14:05:06 -07:00
parent 2e8a54af60
commit 59f108885e
2 changed files with 6 additions and 5 deletions

View File

@ -606,7 +606,7 @@ where
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given `HashMap<K,V>`. The collection may reserve more space to avoid
/// in the given `HashMap<K, V>`. The collection may reserve more space to avoid
/// frequent reallocations.
///
/// # Errors
@ -619,6 +619,7 @@ where
/// ```
/// #![feature(try_reserve)]
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, isize> = HashMap::new();
/// map.try_reserve(10).expect("why is the test harness OOMing on 10 bytes?");
/// ```
@ -898,14 +899,14 @@ where
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all pairs `(k, v)` such that `f(&k,&mut v)` returns `false`.
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
///
/// # Examples
///
/// ```
/// use std::collections::HashMap;
///
/// let mut map: HashMap<i32, i32> = (0..8).map(|x|(x, x*10)).collect();
/// let mut map: HashMap<i32, i32> = (0..8).map(|x| (x, x*10)).collect();
/// map.retain(|&k, _| k % 2 == 0);
/// assert_eq!(map.len(), 4);
/// ```

View File

@ -412,7 +412,7 @@ where
}
/// Tries to reserve capacity for at least `additional` more elements to be inserted
/// in the given `HashSet<K,V>`. The collection may reserve more space to avoid
/// in the given `HashSet<K, V>`. The collection may reserve more space to avoid
/// frequent reallocations.
///
/// # Errors
@ -918,7 +918,7 @@ where
/// ```
/// use std::collections::HashSet;
///
/// let xs = [1,2,3,4,5,6];
/// let xs = [1, 2, 3, 4, 5, 6];
/// let mut set: HashSet<i32> = xs.iter().cloned().collect();
/// set.retain(|&k| k % 2 == 0);
/// assert_eq!(set.len(), 3);