about summary refs log tree commit diff
diff options
context:
space:
mode:
authorphilipp <descpl@yahoo.de>2022-10-15 14:59:27 +0200
committerphilipp <descpl@yahoo.de>2022-10-15 17:47:07 +0200
commit4854e37dbce901db40cc94f078cce87985d7e0b1 (patch)
treec2eff112b0ad2b2d322146198a05279ec2b89375
parentb15e2c129e732fb3f1ff3c707d76341047a66af0 (diff)
downloadrust-4854e37dbce901db40cc94f078cce87985d7e0b1.tar.gz
rust-4854e37dbce901db40cc94f078cce87985d7e0b1.zip
Documentation BTreeMap::append's behavior for already existing keys
-rw-r--r--library/alloc/src/collections/btree/map.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs
index 73bc1c21d55..c4c75e46a2a 100644
--- a/library/alloc/src/collections/btree/map.rs
+++ b/library/alloc/src/collections/btree/map.rs
@@ -1093,6 +1093,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
 
     /// Moves all elements from `other` into `self`, leaving `other` empty.
     ///
+    /// If a key from `other` is already present in `self`, the respective
+    /// value from `self` will be overwritten with the respective value from `other`.
+    ///
     /// # Examples
     ///
     /// ```
@@ -1101,10 +1104,10 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
     /// let mut a = BTreeMap::new();
     /// a.insert(1, "a");
     /// a.insert(2, "b");
-    /// a.insert(3, "c");
+    /// a.insert(3, "c"); // Note: Key (3) also present in b.
     ///
     /// let mut b = BTreeMap::new();
-    /// b.insert(3, "d");
+    /// b.insert(3, "d"); // Note: Key (3) also present in a.
     /// b.insert(4, "e");
     /// b.insert(5, "f");
     ///
@@ -1115,7 +1118,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
     ///
     /// assert_eq!(a[&1], "a");
     /// assert_eq!(a[&2], "b");
-    /// assert_eq!(a[&3], "d");
+    /// assert_eq!(a[&3], "d"); // Note: "c" has been overwritten.
     /// assert_eq!(a[&4], "e");
     /// assert_eq!(a[&5], "f");
     /// ```