@@ -2030,6 +2030,31 @@ impl<'a, K, V> Entry<'a, K, V> {
20302030 Vacant ( entry) => Vacant ( entry) ,
20312031 }
20322032 }
2033+
2034+ /// Sets the value of the entry, and returns an OccupiedEntry.
2035+ ///
2036+ /// # Examples
2037+ ///
2038+ /// ```
2039+ /// #![feature(entry_insert)]
2040+ /// use std::collections::HashMap;
2041+ ///
2042+ /// let mut map: HashMap<&str, String> = HashMap::new();
2043+ /// let entry = map.entry("poneyland").insert("hoho".to_string());
2044+ ///
2045+ /// assert_eq!(entry.key(), &"poneyland");
2046+ /// ```
2047+ #[ inline]
2048+ #[ unstable( feature = "entry_insert" , issue = "65225" ) ]
2049+ pub fn insert ( self , value : V ) -> OccupiedEntry < ' a , K , V > {
2050+ match self {
2051+ Occupied ( mut entry) => {
2052+ entry. insert ( value) ;
2053+ entry
2054+ } ,
2055+ Vacant ( entry) => entry. insert_entry ( value) ,
2056+ }
2057+ }
20332058}
20342059
20352060impl < ' a , K , V : Default > Entry < ' a , K , V > {
@@ -2347,6 +2372,28 @@ impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {
23472372 pub fn insert ( self , value : V ) -> & ' a mut V {
23482373 self . base . insert ( value)
23492374 }
2375+
2376+ /// Sets the value of the entry with the VacantEntry's key,
2377+ /// and returns an OccupiedEntry.
2378+ ///
2379+ /// # Examples
2380+ ///
2381+ /// ```
2382+ /// use std::collections::HashMap;
2383+ /// use std::collections::hash_map::Entry;
2384+ ///
2385+ /// let mut map: HashMap<&str, u32> = HashMap::new();
2386+ ///
2387+ /// if let Entry::Vacant(o) = map.entry("poneyland") {
2388+ /// o.insert(37);
2389+ /// }
2390+ /// assert_eq!(map["poneyland"], 37);
2391+ /// ```
2392+ #[ inline]
2393+ fn insert_entry ( self , value : V ) -> OccupiedEntry < ' a , K , V > {
2394+ let base = self . base . insert_entry ( value) ;
2395+ OccupiedEntry { base }
2396+ }
23502397}
23512398
23522399#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments