about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-11-22 10:37:46 +0100
committerGitHub <noreply@github.com>2018-11-22 10:37:46 +0100
commit89e0fcee4041e038b91dfbe0afbcc1d8306d404d (patch)
tree8d21f44ac7817fe31224146570b50f822a54d39b /src/libstd
parent1c57f0ab9c58d8394b531de15423fbb4c57a2613 (diff)
parent8b750a77fc73290635499494779f77848a8e2b09 (diff)
downloadrust-89e0fcee4041e038b91dfbe0afbcc1d8306d404d.tar.gz
rust-89e0fcee4041e038b91dfbe0afbcc1d8306d404d.zip
Rollup merge of #55784 - meltinglava:master, r=KodrAus
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.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index bb2f152edc6..d4650bd68d6 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -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)
@@ -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 {