about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJack O'Connor <oconnor663@gmail.com>2016-01-30 13:44:45 -0500
committerJack O'Connor <oconnor663@gmail.com>2016-02-15 21:50:30 -0500
commit2cac9d7bd3f26072e101ccabcb4913ef05f46d7c (patch)
tree596f2c2db9eb2077198e574e233de4fb4150ba4c /src/libstd
parent17d284b4b5af8aa2d58c3bf05b937d5b9d1adeb0 (diff)
downloadrust-2cac9d7bd3f26072e101ccabcb4913ef05f46d7c.tar.gz
rust-2cac9d7bd3f26072e101ccabcb4913ef05f46d7c.zip
clarify how insert() doesn't update keys
The first time I read the docs for `insert()`, I thought it was saying
it didn't update existing *values*, and I was confused. Reword the docs
to make it clear that `insert()` does update values.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/collections/hash/map.rs7
-rw-r--r--src/libstd/collections/mod.rs9
2 files changed, 10 insertions, 6 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index 586fafc2b4a..7220690469c 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1157,9 +1157,10 @@ impl<K, V, S> HashMap<K, V, S>
     ///
     /// If the map did not have this key present, `None` is returned.
     ///
-    /// If the map did have this key present, the key is not updated, the
-    /// value is updated and the old value is returned.
-    /// See the [module-level documentation] for more.
+    /// If the map did have this key present, the value is updated, and the old
+    /// value is returned. The key is not updated, though; this matters for
+    /// types that can be `==` without being identical. See the [module-level
+    /// documentation] for more.
     ///
     /// [module-level documentation]: index.html#insert-and-complex-keys
     ///
diff --git a/src/libstd/collections/mod.rs b/src/libstd/collections/mod.rs
index 417261cf4c3..06c14157606 100644
--- a/src/libstd/collections/mod.rs
+++ b/src/libstd/collections/mod.rs
@@ -397,12 +397,15 @@
 //! }
 //!
 //! let mut map = BTreeMap::new();
-//! map.insert(Foo { a: 1, b: "baz" }, ());
+//! map.insert(Foo { a: 1, b: "baz" }, 99);
 //!
 //! // We already have a Foo with an a of 1, so this will be updating the value.
-//! map.insert(Foo { a: 1, b: "xyz" }, ());
+//! map.insert(Foo { a: 1, b: "xyz" }, 100);
 //!
-//! // ... but the key hasn't changed. b is still "baz", not "xyz"
+//! // The value has been updated...
+//! assert_eq!(map.values().next().unwrap(), &100);
+//!
+//! // ...but the key hasn't changed. b is still "baz", not "xyz".
 //! assert_eq!(map.keys().next().unwrap().b, "baz");
 //! ```