Rollup merge of #90345 - passcod:entry-insert, r=dtolnay

Stabilise entry_insert

This stabilises `HashMap:Entry::insert_entry` etc. Tracking issue #65225. It will need an FCP.

This was implemented in #64656 two years ago.

This PR includes the rename and change discussed in https://github.com/rust-lang/rust/issues/65225#issuecomment-910652430, happy to split if needed.
This commit is contained in:
Matthias Krüger 2021-12-21 08:33:37 +01:00 committed by GitHub
commit 3009dd7c5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2462,17 +2462,16 @@ pub fn and_modify<F>(self, f: F) -> Self
/// # Examples
///
/// ```
/// #![feature(entry_insert)]
/// use std::collections::HashMap;
///
/// let mut map: HashMap<&str, String> = HashMap::new();
/// let entry = map.entry("poneyland").insert("hoho".to_string());
/// let entry = map.entry("poneyland").insert_entry("hoho".to_string());
///
/// assert_eq!(entry.key(), &"poneyland");
/// ```
#[inline]
#[unstable(feature = "entry_insert", issue = "65225")]
pub fn insert(self, value: V) -> OccupiedEntry<'a, K, V> {
#[stable(feature = "entry_insert", since = "1.59.0")]
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
match self {
Occupied(mut entry) => {
entry.insert(value);
@ -2811,12 +2810,13 @@ pub fn insert(self, value: V) -> &'a mut V {
/// let mut map: HashMap<&str, u32> = HashMap::new();
///
/// if let Entry::Vacant(o) = map.entry("poneyland") {
/// o.insert(37);
/// o.insert_entry(37);
/// }
/// assert_eq!(map["poneyland"], 37);
/// ```
#[inline]
fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
#[stable(feature = "entry_insert", since = "1.59.0")]
pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, K, V> {
let base = self.base.insert_entry(value);
OccupiedEntry { base }
}