Skip to content

Commit 2e5b775

Browse files
committed
Deprecate hashmap's find_copy and get_copy in favour of cloned and clone
1 parent c0a60c1 commit 2e5b775

File tree

1 file changed

+7
-1
lines changed
  • src/libstd/collections/hash

1 file changed

+7
-1
lines changed

src/libstd/collections/hash/map.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,8 @@ fn search_entry_hashed<'a, K: Eq, V>(table: &'a mut RawTable<K,V>, hash: SafeHas
12211221
}
12221222

12231223
impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
1224+
/// Deprecated: Use `map.get(k).cloned()`.
1225+
///
12241226
/// Return a copy of the value corresponding to the key.
12251227
///
12261228
/// # Example
@@ -1232,10 +1234,13 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
12321234
/// map.insert(1u, "foo".to_string());
12331235
/// let s: String = map.find_copy(&1).unwrap();
12341236
/// ```
1237+
#[deprecated = "Use `map.get(k).cloned()`"]
12351238
pub fn find_copy(&self, k: &K) -> Option<V> {
1236-
self.get(k).map(|v| (*v).clone())
1239+
self.get(k).cloned()
12371240
}
12381241

1242+
/// Deprecated: Use `map[k].clone()`.
1243+
///
12391244
/// Return a copy of the value corresponding to the key.
12401245
///
12411246
/// # Failure
@@ -1251,6 +1256,7 @@ impl<K: Eq + Hash<S>, V: Clone, S, H: Hasher<S>> HashMap<K, V, H> {
12511256
/// map.insert(1u, "foo".to_string());
12521257
/// let s: String = map.get_copy(&1);
12531258
/// ```
1259+
#[deprecated = "Use `map[k].clone()`"]
12541260
pub fn get_copy(&self, k: &K) -> V {
12551261
self[*k].clone()
12561262
}

0 commit comments

Comments
 (0)