]> git.lizzy.rs Git - rust.git/commitdiff
Add Entry::key
authorSteven Fackler <sfackler@gmail.com>
Fri, 22 Apr 2016 05:19:49 +0000 (22:19 -0700)
committerSteven Fackler <sfackler@gmail.com>
Fri, 22 Apr 2016 05:19:49 +0000 (22:19 -0700)
This method was present on both variants of Entry, but not the enum

cc #32281

src/libcollections/btree/map.rs
src/libstd/collections/hash/map.rs

index de40568fd6704d97f0cb4399efca81113993055b..0dbdad98c8672597eb60cda0d12f1d5efedcd4c9 100644 (file)
@@ -1522,6 +1522,15 @@ pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut 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> {
index c20270e830665d4ee0eb36d3bef5b9352f62166d..4b5696b79133a392e197065f3c4e1e10db5f6a90 100644 (file)
@@ -1533,6 +1533,15 @@ pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut 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> {