Skip to content

Commit e31ae4f

Browse files
authored
Rollup merge of #103087 - phimuemue:btreemap_append_doc, r=Mark-Simulacrum
Documentation BTreeMap::append's behavior for already existing keys `BTreeMap::append` overwrites existing values with new ones. This commit adds explicit documentation for that.
2 parents bf286a8 + 4854e37 commit e31ae4f

File tree

1 file changed

+6
-3
lines changed
  • library/alloc/src/collections/btree

1 file changed

+6
-3
lines changed

library/alloc/src/collections/btree/map.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
10931093

10941094
/// Moves all elements from `other` into `self`, leaving `other` empty.
10951095
///
1096+
/// If a key from `other` is already present in `self`, the respective
1097+
/// value from `self` will be overwritten with the respective value from `other`.
1098+
///
10961099
/// # Examples
10971100
///
10981101
/// ```
@@ -1101,10 +1104,10 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11011104
/// let mut a = BTreeMap::new();
11021105
/// a.insert(1, "a");
11031106
/// a.insert(2, "b");
1104-
/// a.insert(3, "c");
1107+
/// a.insert(3, "c"); // Note: Key (3) also present in b.
11051108
///
11061109
/// let mut b = BTreeMap::new();
1107-
/// b.insert(3, "d");
1110+
/// b.insert(3, "d"); // Note: Key (3) also present in a.
11081111
/// b.insert(4, "e");
11091112
/// b.insert(5, "f");
11101113
///
@@ -1115,7 +1118,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11151118
///
11161119
/// assert_eq!(a[&1], "a");
11171120
/// assert_eq!(a[&2], "b");
1118-
/// assert_eq!(a[&3], "d");
1121+
/// assert_eq!(a[&3], "d"); // Note: "c" has been overwritten.
11191122
/// assert_eq!(a[&4], "e");
11201123
/// assert_eq!(a[&5], "f");
11211124
/// ```

0 commit comments

Comments
 (0)