Skip to content

Commit 4ba7f33

Browse files
committed
Auto merge of #425 - programmerjake:change-key-to-return-k, r=Amanieu
Change key to return `&K` rather than `&Q` also changes `EntryRef::and_replace_entry_with` and `OccupiedEntryRef::replace_entry_with` to also give out `&K` Fixes: #421
2 parents e8c96d0 + e72ced8 commit 4ba7f33

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

src/map.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,7 +4562,7 @@ impl<K: Borrow<Q>, Q: ?Sized + Debug, V: Debug, S, A: Allocator + Clone> Debug
45624562
{
45634563
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
45644564
f.debug_struct("OccupiedEntryRef")
4565-
.field("key", &self.key())
4565+
.field("key", &self.key().borrow())
45664566
.field("value", &self.get())
45674567
.finish()
45684568
}
@@ -5832,7 +5832,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V,
58325832
K: Borrow<Q>,
58335833
{
58345834
match *self {
5835-
EntryRef::Occupied(ref entry) => entry.key(),
5835+
EntryRef::Occupied(ref entry) => entry.key().borrow(),
58365836
EntryRef::Vacant(ref entry) => entry.key(),
58375837
}
58385838
}
@@ -5928,8 +5928,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> EntryRef<'a, 'b, K, Q, V,
59285928
#[cfg_attr(feature = "inline-more", inline)]
59295929
pub fn and_replace_entry_with<F>(self, f: F) -> Self
59305930
where
5931-
F: FnOnce(&Q, V) -> Option<V>,
5932-
K: Borrow<Q>,
5931+
F: FnOnce(&K, V) -> Option<V>,
59335932
{
59345933
match self {
59355934
EntryRef::Occupied(entry) => entry.replace_entry_with(f),
@@ -5988,11 +5987,8 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b,
59885987
/// }
59895988
/// ```
59905989
#[cfg_attr(feature = "inline-more", inline)]
5991-
pub fn key(&self) -> &Q
5992-
where
5993-
K: Borrow<Q>,
5994-
{
5995-
unsafe { &self.elem.as_ref().0 }.borrow()
5990+
pub fn key(&self) -> &K {
5991+
unsafe { &self.elem.as_ref().0 }
59965992
}
59975993

59985994
/// Take the ownership of the key and value from the map.
@@ -6297,16 +6293,15 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator + Clone> OccupiedEntryRef<'a, 'b,
62976293
#[cfg_attr(feature = "inline-more", inline)]
62986294
pub fn replace_entry_with<F>(self, f: F) -> EntryRef<'a, 'b, K, Q, V, S, A>
62996295
where
6300-
F: FnOnce(&Q, V) -> Option<V>,
6301-
K: Borrow<Q>,
6296+
F: FnOnce(&K, V) -> Option<V>,
63026297
{
63036298
unsafe {
63046299
let mut spare_key = None;
63056300

63066301
self.table
63076302
.table
63086303
.replace_bucket_with(self.elem.clone(), |(key, value)| {
6309-
if let Some(new_value) = f(key.borrow(), value) {
6304+
if let Some(new_value) = f(&key, value) {
63106305
Some((key, new_value))
63116306
} else {
63126307
spare_key = Some(KeyOrRef::Owned(key));

0 commit comments

Comments
 (0)