Stabilize or_insert_with_key
This commit is contained in:
parent
98e16884b1
commit
c2de8fe294
3 changed files with 3 additions and 5 deletions
|
@ -40,7 +40,7 @@ const SSO_ARRAY_SIZE: usize = 8;
|
||||||
// into_keys/into_values (unstable)
|
// into_keys/into_values (unstable)
|
||||||
// all raw_entry-related
|
// all raw_entry-related
|
||||||
// PartialEq/Eq (requires sorting the array)
|
// PartialEq/Eq (requires sorting the array)
|
||||||
// Entry::or_insert_with_key (unstable)
|
// Entry::or_insert_with_key
|
||||||
// Vacant/Occupied entries and related
|
// Vacant/Occupied entries and related
|
||||||
//
|
//
|
||||||
// FIXME: In HashMap most methods accepting key reference
|
// FIXME: In HashMap most methods accepting key reference
|
||||||
|
|
|
@ -116,7 +116,6 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[unstable(feature = "or_insert_with_key", issue = "71024")]
|
|
||||||
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
|
/// Ensures a value is in the entry by inserting, if empty, the result of the default function,
|
||||||
/// which takes the key as its argument, and returns a mutable reference to the value in the
|
/// which takes the key as its argument, and returns a mutable reference to the value in the
|
||||||
/// entry.
|
/// entry.
|
||||||
|
@ -124,7 +123,6 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(or_insert_with_key)]
|
|
||||||
/// use std::collections::BTreeMap;
|
/// use std::collections::BTreeMap;
|
||||||
///
|
///
|
||||||
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
|
/// let mut map: BTreeMap<&str, usize> = BTreeMap::new();
|
||||||
|
@ -134,6 +132,7 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
|
||||||
/// assert_eq!(map["poneyland"], 9);
|
/// assert_eq!(map["poneyland"], 9);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[stable(feature = "or_insert_with_key", since = "1.49.0")]
|
||||||
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
||||||
match self {
|
match self {
|
||||||
Occupied(entry) => entry.into_mut(),
|
Occupied(entry) => entry.into_mut(),
|
||||||
|
|
|
@ -2229,7 +2229,6 @@ impl<'a, K, V> Entry<'a, K, V> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(or_insert_with_key)]
|
|
||||||
/// use std::collections::HashMap;
|
/// use std::collections::HashMap;
|
||||||
///
|
///
|
||||||
/// let mut map: HashMap<&str, usize> = HashMap::new();
|
/// let mut map: HashMap<&str, usize> = HashMap::new();
|
||||||
|
@ -2239,7 +2238,7 @@ impl<'a, K, V> Entry<'a, K, V> {
|
||||||
/// assert_eq!(map["poneyland"], 9);
|
/// assert_eq!(map["poneyland"], 9);
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[unstable(feature = "or_insert_with_key", issue = "71024")]
|
#[stable(feature = "or_insert_with_key", since = "1.49.0")]
|
||||||
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
pub fn or_insert_with_key<F: FnOnce(&K) -> V>(self, default: F) -> &'a mut V {
|
||||||
match self {
|
match self {
|
||||||
Occupied(entry) => entry.into_mut(),
|
Occupied(entry) => entry.into_mut(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue