diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2016-02-17 18:14:36 -0500 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2016-02-17 18:14:36 -0500 |
| commit | 27ef9df824e2d5b0e22b48dfcfc19906e1ea35ca (patch) | |
| tree | f4a630e16147ea2289f49c10b18f2ae341b12078 /src/libstd | |
| parent | 0a88c8fb197fa10eb36c10215066b87badd3b67b (diff) | |
| parent | 2cac9d7bd3f26072e101ccabcb4913ef05f46d7c (diff) | |
| download | rust-27ef9df824e2d5b0e22b48dfcfc19906e1ea35ca.tar.gz rust-27ef9df824e2d5b0e22b48dfcfc19906e1ea35ca.zip | |
Rollup merge of #31694 - oconnor663:insertdocs, r=steveklabnik
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.rs | 7 | ||||
| -rw-r--r-- | src/libstd/collections/mod.rs | 9 |
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"); //! ``` |
