From 9e167ef60ac6201971867a74a6d00628fd7a0106 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 21 Apr 2016 22:19:49 -0700 Subject: [PATCH] Add Entry::key This method was present on both variants of Entry, but not the enum cc #32281 --- src/libcollections/btree/map.rs | 9 +++++++++ src/libstd/collections/hash/map.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index de40568fd67..0dbdad98c86 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -1522,6 +1522,15 @@ impl<'a, K: Ord, V> Entry<'a, K, V> { Vacant(entry) => entry.insert(default()), } } + + /// Returns a reference to this entry's key. + #[unstable(feature = "map_entry_keys", issue = "32281")] + pub fn key(&self) -> &K { + match *self { + Occupied(ref entry) => entry.key(), + Vacant(ref entry) => entry.key(), + } + } } impl<'a, K: Ord, V> VacantEntry<'a, K, V> { diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index c20270e8306..4b5696b7913 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1533,6 +1533,15 @@ impl<'a, K, V> Entry<'a, K, V> { Vacant(entry) => entry.insert(default()), } } + + /// Returns a reference to this entry's key. + #[unstable(feature = "map_entry_keys", issue = "32281")] + pub fn key(&self) -> &K { + match *self { + Occupied(ref entry) => entry.key(), + Vacant(ref entry) => entry.key(), + } + } } impl<'a, K, V> OccupiedEntry<'a, K, V> {