Skip to content

Commit 9e167ef

Browse files
committed
Add Entry::key
This method was present on both variants of Entry, but not the enum cc #32281
1 parent b5ba592 commit 9e167ef

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/libcollections/btree/map.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,15 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
15221522
Vacant(entry) => entry.insert(default()),
15231523
}
15241524
}
1525+
1526+
/// Returns a reference to this entry's key.
1527+
#[unstable(feature = "map_entry_keys", issue = "32281")]
1528+
pub fn key(&self) -> &K {
1529+
match *self {
1530+
Occupied(ref entry) => entry.key(),
1531+
Vacant(ref entry) => entry.key(),
1532+
}
1533+
}
15251534
}
15261535

15271536
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {

src/libstd/collections/hash/map.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,15 @@ impl<'a, K, V> Entry<'a, K, V> {
15331533
Vacant(entry) => entry.insert(default()),
15341534
}
15351535
}
1536+
1537+
/// Returns a reference to this entry's key.
1538+
#[unstable(feature = "map_entry_keys", issue = "32281")]
1539+
pub fn key(&self) -> &K {
1540+
match *self {
1541+
Occupied(ref entry) => entry.key(),
1542+
Vacant(ref entry) => entry.key(),
1543+
}
1544+
}
15361545
}
15371546

15381547
impl<'a, K, V> OccupiedEntry<'a, K, V> {

0 commit comments

Comments
 (0)