mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-30 08:34:07 +00:00
Rollup merge of #97611 - azdavis:master, r=Dylan-DPC
Tweak insert docs For `{Hash, BTree}Map::insert`, I always have to take a few extra seconds to think about the slight weirdness about the fact that if we "did not" insert (which "sounds" false), we return true, and if we "did" insert, (which "sounds" true), we return false. This tweaks the doc comments for the `insert` methods of those types (as well as what looks like a rustc internal data structure that I found just by searching the codebase for "If the set did") to first use the "Returns whether _something_" pattern used in e.g. `remove`, where we say that `remove` "returns whether the value was present".
This commit is contained in:
commit
2c3a8cf0a4
@ -126,9 +126,10 @@ impl<T: Eq + Hash> SsoHashSet<T> {
|
||||
|
||||
/// Adds a value to the set.
|
||||
///
|
||||
/// If the set did not have this value present, `true` is returned.
|
||||
/// Returns whether the value was newly inserted. That is:
|
||||
///
|
||||
/// If the set did have this value present, `false` is returned.
|
||||
/// - If the set did not previously contain this value, `true` is returned.
|
||||
/// - If the set already contained this value, `false` is returned.
|
||||
#[inline]
|
||||
pub fn insert(&mut self, elem: T) -> bool {
|
||||
self.map.insert(elem, ()).is_none()
|
||||
|
@ -770,10 +770,14 @@ impl<T> BTreeSet<T> {
|
||||
|
||||
/// Adds a value to the set.
|
||||
///
|
||||
/// If the set did not have an equal element present, `true` is returned.
|
||||
/// Returns whether the value was newly inserted. That is:
|
||||
///
|
||||
/// If the set did have an equal element present, `false` is returned, and
|
||||
/// the entry is not updated. See the [module-level documentation] for more.
|
||||
/// - If the set did not previously contain an equal value, `true` is
|
||||
/// returned.
|
||||
/// - If the set already contained an equal value, `false` is returned, and
|
||||
/// the entry is not updated.
|
||||
///
|
||||
/// See the [module-level documentation] for more.
|
||||
///
|
||||
/// [module-level documentation]: index.html#insert-and-complex-keys
|
||||
///
|
||||
|
@ -858,9 +858,10 @@ where
|
||||
|
||||
/// Adds a value to the set.
|
||||
///
|
||||
/// If the set did not have this value present, `true` is returned.
|
||||
/// Returns whether the value was newly inserted. That is:
|
||||
///
|
||||
/// If the set did have this value present, `false` is returned.
|
||||
/// - If the set did not previously contain this value, `true` is returned.
|
||||
/// - If the set already contained this value, `false` is returned.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user