Skip to content

Commit

Permalink
Add Entry::key
Browse files Browse the repository at this point in the history
This method was present on both variants of Entry, but not the enum

cc rust-lang#32281
  • Loading branch information
sfackler committed Apr 22, 2016
1 parent b5ba592 commit 9e167ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
9 changes: 9 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 9e167ef

Please sign in to comment.