mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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.
This commit is contained in:
parent
17d284b4b5
commit
2cac9d7bd3
@ -375,9 +375,10 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
||||
///
|
||||
/// 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
|
||||
///
|
||||
|
@ -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
|
||||
///
|
||||
|
@ -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");
|
||||
//! ```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user