Auto merge of #33148 - sfackler:entry-key, r=alexcrichton

Add Entry::key

This method was present on both variants of Entry, but not the enum

cc #32281

r? @alexcrichton
This commit is contained in:
bors 2016-04-29 18:11:25 -07:00
commit 46504e9a9d
2 changed files with 18 additions and 0 deletions

View File

@ -1654,6 +1654,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> {

View File

@ -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> {