Skip to content

Commit

Permalink
Rollup merge of rust-lang#55784 - meltinglava:master, r=KodrAus
Browse files Browse the repository at this point in the history
Clarifying documentation for collections::hash_map::Entry::or_insert

Previous version does not show that or_insert does not insert the passed value, as the passed value was the same value as what was already in the map.
  • Loading branch information
GuillaumeGomez committed Nov 22, 2018
2 parents 1c57f0a + 8b750a7 commit 89e0fce
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,12 +2026,12 @@ impl<'a, K, V, S> RawEntryMut<'a, K, V, S> {
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, u32> = HashMap::new();
/// map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 12);
///
/// assert_eq!(map["poneyland"], 12);
/// map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 3);
/// assert_eq!(map["poneyland"], 3);
///
/// *map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 12).1 += 10;
/// assert_eq!(map["poneyland"], 22);
/// *map.raw_entry_mut().from_key("poneyland").or_insert("poneyland", 10).1 *= 2;
/// assert_eq!(map["poneyland"], 6);
/// ```
#[unstable(feature = "hash_raw_entry", issue = "54043")]
pub fn or_insert(self, default_key: K, default_val: V) -> (&'a mut K, &'a mut V)
Expand Down Expand Up @@ -2648,12 +2648,12 @@ impl<'a, K, V> Entry<'a, K, V> {
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, u32> = HashMap::new();
/// map.entry("poneyland").or_insert(12);
///
/// assert_eq!(map["poneyland"], 12);
/// map.entry("poneyland").or_insert(3);
/// assert_eq!(map["poneyland"], 3);
///
/// *map.entry("poneyland").or_insert(12) += 10;
/// assert_eq!(map["poneyland"], 22);
/// *map.entry("poneyland").or_insert(10) *= 2;
/// assert_eq!(map["poneyland"], 6);
/// ```
pub fn or_insert(self, default: V) -> &'a mut V {
match self {
Expand Down

0 comments on commit 89e0fce

Please sign in to comment.