Add Entry::key

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

cc #32281
This commit is contained in:
Steven Fackler 2016-04-21 22:19:49 -07:00
parent b5ba5923f8
commit 9e167ef60a
2 changed files with 18 additions and 0 deletions

View file

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

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