@@ -4383,35 +4383,35 @@ impl<'map, 'key, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'map, 'key, K,
43834383 & mut entry. 1
43844384 }
43854385
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- /// ```compile_fail
4391- /// # use hashbrown::hash_map::EntryRef;
4392- /// # use hashbrown::HashMap;
4393- /// // note that our key is a (small) tuple
4394- /// let mut h = HashMap::<(String,), char>::new();
4395- /// let k = (String::from("c"),);
4396- /// match h.entry_ref(&k) {
4397- /// // fails here, as &(i32) does not implement Into<(i32)>
4398- /// EntryRef::Vacant(r) => r.insert('c'),
4399- /// EntryRef::Occupied(r) => r.get(),
4400- /// };
4401- /// ```
4386+ /// Sets the key and value of the entry and returns a mutable reference to
4387+ /// the inserted value.
4388+ ///
4389+ /// Unlike [`VacantEntryRef::insert`], this method allows the key to be
4390+ /// explicitly specified, which is useful for key types that don't implement
4391+ /// `K: From<&Q>`.
4392+ ///
4393+ /// # Panics
4394+ ///
4395+ /// This method panics if `key` is not equivalent to the key used to create
4396+ /// the `VacantEntryRef`.
4397+ ///
4398+ /// # Example
4399+ ///
44024400 /// ```
4403- /// # use hashbrown::hash_map::EntryRef;
4404- /// # use hashbrown::HashMap;
4405- /// let mut h = HashMap::<(String,), char>::new();
4406- /// let k = (String::from("c"),);
4407- /// match h.entry_ref(&k) {
4408- /// // works, because we manually clone when needed.
4409- /// EntryRef::Vacant(r) => r.insert_with_key(k.clone(),'c'),
4410- /// // in this branch we avoided the clone
4411- /// EntryRef::Occupied(r) => r.get(),
4401+ /// use hashbrown::hash_map::EntryRef;
4402+ /// use hashbrown::HashMap;
4403+ ///
4404+ /// let mut map = HashMap::<(String, String), char>::new();
4405+ /// let k = ("c".to_string(), "C".to_string());
4406+ /// let v = match map.entry_ref(&k) {
4407+ /// // Insert cannot be used here because tuples do not implement From.
4408+ /// // However this works because we can manually clone instead.
4409+ /// EntryRef::Vacant(r) => r.insert_with_key(k.clone(), 'c'),
4410+ /// // In this branch we avoid the clone.
4411+ /// EntryRef::Occupied(r) => r.into_mut(),
44124412 /// };
4413+ /// assert_eq!(*v, 'c');
44134414 /// ```
4414- ///
44154415 #[ cfg_attr( feature = "inline-more" , inline) ]
44164416 pub fn insert_with_key ( self , key : K , value : V ) -> & ' map mut V
44174417 where
@@ -4422,7 +4422,7 @@ impl<'map, 'key, K, Q: ?Sized, V, S, A: Allocator> VacantEntryRef<'map, 'key, K,
44224422 let table = & mut self . table . table ;
44234423 assert ! (
44244424 ( self . key) . equivalent( & key) ,
4425- "The key used for Entry creation and the one used for insertion are not equivalent "
4425+ "key used for Entry creation is not equivalent to the one used for insertion"
44264426 ) ;
44274427 let entry = table. insert_entry (
44284428 self . hash ,
0 commit comments