Skip to content

Commit

Permalink
Improved documentation for HashMap/BTreeMap Entry's .or_insert_with_k…
Browse files Browse the repository at this point in the history
…ey method
  • Loading branch information
ChaiTRex committed Dec 8, 2020
1 parent 866ef87 commit f1b930d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions library/alloc/src/collections/btree/map/entry.rs
Expand Up @@ -116,9 +116,12 @@ impl<'a, K: Ord, V> Entry<'a, K, V> {
}
}

/// 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
/// entry.
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
/// This method allows for generating key-derived values for insertion by providing the default
/// function a reference to the key that was moved during the `.entry(key)` method call.<br />
///
/// The reference to the moved key is provided so that cloning or copying the key is
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
///
/// # Examples
///
Expand Down
9 changes: 6 additions & 3 deletions library/std/src/collections/hash/map.rs
Expand Up @@ -2222,9 +2222,12 @@ impl<'a, K, V> Entry<'a, K, V> {
}
}

/// 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
/// entry.
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
/// This method allows for generating key-derived values for insertion by providing the default
/// function a reference to the key that was moved during the `.entry(key)` method call.
///
/// The reference to the moved key is provided so that cloning or copying the key is
/// unnecessary, unlike with `.or_insert_with(|| ... )`.
///
/// # Examples
///
Expand Down

0 comments on commit f1b930d

Please sign in to comment.