Add Entry::key
This method was present on both variants of Entry, but not the enum cc #32281
This commit is contained in:
parent
b5ba5923f8
commit
9e167ef60a
2 changed files with 18 additions and 0 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue