Addressed @BurntSuchi's remarks regarding Entry::replace
This commit is contained in:
parent
a312b47698
commit
d3de465dc8
@ -2167,21 +2167,20 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
|
|||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # #![feature(map_entry_replace)]
|
/// #![feature(map_entry_replace)]
|
||||||
/// use std::collections::HashMap;
|
/// use std::collections::HashMap;
|
||||||
/// use std::collections::hash_map::Entry;
|
/// use std::collections::hash_map::Entry;
|
||||||
///
|
///
|
||||||
/// let mut map: HashMap<String, u32> = HashMap::new();
|
/// let mut map: HashMap<String, u32> = HashMap::new();
|
||||||
/// map.insert(String::from("poneyland"), 15);
|
/// map.insert("poneyland".to_string(), 15);
|
||||||
///
|
///
|
||||||
/// if let Entry::Occupied(entry) = map.entry(String::from("poneyland")) {
|
/// if let Entry::Occupied(entry) = map.entry("poneyland".to_string()) {
|
||||||
/// let (old_key, old_value): (String, u32) = entry.replace(16);
|
/// let (old_key, old_value): (String, u32) = entry.replace(16);
|
||||||
/// assert_eq!(old_key, "poneyland");
|
/// assert_eq!(old_key, "poneyland");
|
||||||
/// assert_eq!(old_value, 15);
|
/// assert_eq!(old_value, 15);
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// assert_eq!(map.get("poneyland"), Some(&16));
|
/// assert_eq!(map.get("poneyland"), Some(&16));
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "map_entry_replace", issue = "44286")]
|
#[unstable(feature = "map_entry_replace", issue = "44286")]
|
||||||
pub fn replace(mut self, value: V) -> (K, V) {
|
pub fn replace(mut self, value: V) -> (K, V) {
|
||||||
|
Loading…
Reference in New Issue
Block a user