Skip to content

Commit

Permalink
Auto merge of #33148 - sfackler:entry-key, r=alexcrichton
Browse files Browse the repository at this point in the history
Add Entry::key

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

cc #32281

r? @alexcrichton
  • Loading branch information
bors committed Apr 30, 2016
2 parents 9b63263 + 9e167ef commit 46504e9
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 @@ -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> {
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 46504e9

Please sign in to comment.