@@ -2983,10 +2983,10 @@ where
2983
2983
/// }
2984
2984
/// assert!(map["b"] == 20 && map.len() == 2);
2985
2985
/// ```
2986
- pub struct VacantEntryRef < ' a , ' b , K , Q : ?Sized , V , S , A : Allocator = Global > {
2986
+ pub struct VacantEntryRef < ' map , ' key , K , Q : ?Sized , V , S , A : Allocator = Global > {
2987
2987
hash : u64 ,
2988
- key : & ' b Q ,
2989
- table : & ' a mut HashMap < K , V , S , A > ,
2988
+ key : & ' key Q ,
2989
+ table : & ' map mut HashMap < K , V , S , A > ,
2990
2990
}
2991
2991
2992
2992
impl < K , Q , V , S , A > Debug for VacantEntryRef < ' _ , ' _ , K , Q , V , S , A >
@@ -4332,7 +4332,7 @@ impl<'a, 'b, K, Q: ?Sized, V: Default, S, A: Allocator> EntryRef<'a, 'b, K, Q, V
4332
4332
}
4333
4333
}
4334
4334
4335
- impl < ' a , ' b , K , Q : ?Sized , V , S , A : Allocator > VacantEntryRef < ' a , ' b , K , Q , V , S , A > {
4335
+ impl < ' map , ' key , K , Q : ?Sized , V , S , A : Allocator > VacantEntryRef < ' map , ' key , K , Q , V , S , A > {
4336
4336
/// Gets a reference to the key that would be used when inserting a value
4337
4337
/// through the `VacantEntryRef`.
4338
4338
///
@@ -4346,7 +4346,7 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'a, 'b, K, Q, V, S
4346
4346
/// assert_eq!(map.entry_ref(key).key(), "poneyland");
4347
4347
/// ```
4348
4348
#[ cfg_attr( feature = "inline-more" , inline) ]
4349
- pub fn key ( & self ) -> & ' b Q {
4349
+ pub fn key ( & self ) -> & ' key Q {
4350
4350
self . key
4351
4351
}
4352
4352
@@ -4368,10 +4368,10 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'a, 'b, K, Q, V, S
4368
4368
/// assert_eq!(map["poneyland"], 37);
4369
4369
/// ```
4370
4370
#[ cfg_attr( feature = "inline-more" , inline) ]
4371
- pub fn insert ( self , value : V ) -> & ' a mut V
4371
+ pub fn insert ( self , value : V ) -> & ' map mut V
4372
4372
where
4373
4373
K : Hash ,
4374
- & ' b Q : Into < K > ,
4374
+ & ' key Q : Into < K > ,
4375
4375
S : BuildHasher ,
4376
4376
{
4377
4377
let table = & mut self . table . table ;
@@ -4383,6 +4383,27 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'a, 'b, K, Q, V, S
4383
4383
& mut entry. 1
4384
4384
}
4385
4385
4386
+ /// [insert](Self::insert) a value by providing the key at insertion time.
4387
+ /// Returns a mutable reference to the inserted value.
4388
+ ///
4389
+ /// Useful if Into is not implemented for converting from &Q to K.
4390
+ #[ cfg_attr( feature = "inline-more" , inline) ]
4391
+ pub fn insert_with_key ( self , key : K , value : V ) -> & ' map mut V
4392
+ where
4393
+ K : Hash ,
4394
+ Q : Equivalent < K > ,
4395
+ S : BuildHasher ,
4396
+ {
4397
+ let table = & mut self . table . table ;
4398
+ assert ! ( ( & self . key) . equivalent( & key) ) ;
4399
+ let entry = table. insert_entry (
4400
+ self . hash ,
4401
+ ( key, value) ,
4402
+ make_hasher :: < _ , V , S > ( & self . table . hash_builder ) ,
4403
+ ) ;
4404
+ & mut entry. 1
4405
+ }
4406
+
4386
4407
/// Sets the value of the entry with the [`VacantEntryRef`]'s key,
4387
4408
/// and returns an [`OccupiedEntry`].
4388
4409
///
@@ -4400,10 +4421,10 @@ impl<'a, 'b, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'a, 'b, K, Q, V, S
4400
4421
/// }
4401
4422
/// ```
4402
4423
#[ cfg_attr( feature = "inline-more" , inline) ]
4403
- pub fn insert_entry ( self , value : V ) -> OccupiedEntry < ' a , K , V , S , A >
4424
+ pub fn insert_entry ( self , value : V ) -> OccupiedEntry < ' map , K , V , S , A >
4404
4425
where
4405
4426
K : Hash ,
4406
- & ' b Q : Into < K > ,
4427
+ & ' key Q : Into < K > ,
4407
4428
S : BuildHasher ,
4408
4429
{
4409
4430
let elem = self . table . table . insert (
0 commit comments