Skip to content

Commit f1b930d

Browse files
committed
Improved documentation for HashMap/BTreeMap Entry's .or_insert_with_key method
1 parent 866ef87 commit f1b930d

File tree

2 files changed

+12
-6
lines changed
  • library

2 files changed

+12
-6
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
116116
}
117117
}
118118

119-
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
120-
/// which takes the key as its argument, and returns a mutable reference to the value in the
121-
/// entry.
119+
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
120+
/// This method allows for generating key-derived values for insertion by providing the default
121+
/// function a reference to the key that was moved during the `.entry(key)` method call.<br />
122+
///
123+
/// The reference to the moved key is provided so that cloning or copying the key is
124+
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
122125
///
123126
/// # Examples
124127
///

library/std/src/collections/hash/map.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,9 +2222,12 @@ impl<'a, K, V> Entry<'a, K, V> {
22222222
}
22232223
}
22242224

2225-
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
2226-
/// which takes the key as its argument, and returns a mutable reference to the value in the
2227-
/// entry.
2225+
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
2226+
/// This method allows for generating key-derived values for insertion by providing the default
2227+
/// function a reference to the key that was moved during the `.entry(key)` method call.
2228+
///
2229+
/// The reference to the moved key is provided so that cloning or copying the key is
2230+
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
22282231
///
22292232
/// # Examples
22302233
///

0 commit comments

Comments
 (0)