Skip to content

Commit 3338ff7

Browse files
authored
Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-Simulacrum
Docs(lib): Fix `extract_if` docs Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change. `@rustbot` label T-libs A-collections A-docs
2 parents 3f91bbc + b1d7480 commit 3338ff7

File tree

5 files changed

+29
-27
lines changed

5 files changed

+29
-27
lines changed

library/alloc/src/collections/btree/map.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,10 +1398,12 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
13981398
}
13991399

14001400
/// Creates an iterator that visits all elements (key-value pairs) in
1401-
/// ascending key order and uses a closure to determine if an element should
1402-
/// be removed. If the closure returns `true`, the element is removed from
1403-
/// the map and yielded. If the closure returns `false`, or panics, the
1404-
/// element remains in the map and will not be yielded.
1401+
/// ascending key order and uses a closure to determine if an element
1402+
/// should be removed.
1403+
///
1404+
/// If the closure returns `true`, the element is removed from the map and
1405+
/// yielded. If the closure returns `false`, or panics, the element remains
1406+
/// in the map and will not be yielded.
14051407
///
14061408
/// The iterator also lets you mutate the value of each element in the
14071409
/// closure, regardless of whether you choose to keep or remove it.

library/alloc/src/collections/linked_list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,20 +1124,20 @@ impl<T, A: Allocator> LinkedList<T, A> {
11241124

11251125
/// Creates an iterator which uses a closure to determine if an element should be removed.
11261126
///
1127-
/// If the closure returns true, then the element is removed and yielded.
1128-
/// If the closure returns false, the element will remain in the list and will not be yielded
1129-
/// by the iterator.
1127+
/// If the closure returns `true`, the element is removed from the list and
1128+
/// yielded. If the closure returns `false`, or panics, the element remains
1129+
/// in the list and will not be yielded.
11301130
///
11311131
/// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating
11321132
/// or the iteration short-circuits, then the remaining elements will be retained.
11331133
/// Use `extract_if().for_each(drop)` if you do not need the returned iterator.
11341134
///
1135-
/// Note that `extract_if` lets you mutate every element in the filter closure, regardless of
1136-
/// whether you choose to keep or remove it.
1135+
/// The iterator also lets you mutate the value of each element in the
1136+
/// closure, regardless of whether you choose to keep or remove it.
11371137
///
11381138
/// # Examples
11391139
///
1140-
/// Splitting a list into evens and odds, reusing the original list:
1140+
/// Splitting a list into even and odd values, reusing the original list:
11411141
///
11421142
/// ```
11431143
/// use std::collections::LinkedList;

library/alloc/src/vec/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3648,11 +3648,11 @@ impl<T, A: Allocator> Vec<T, A> {
36483648
Splice { drain: self.drain(range), replace_with: replace_with.into_iter() }
36493649
}
36503650

3651-
/// Creates an iterator which uses a closure to determine if element in the range should be removed.
3651+
/// Creates an iterator which uses a closure to determine if an element in the range should be removed.
36523652
///
3653-
/// If the closure returns true, then the element is removed and yielded.
3654-
/// If the closure returns false, the element will remain in the vector and will not be yielded
3655-
/// by the iterator.
3653+
/// If the closure returns `true`, the element is removed from the vector
3654+
/// and yielded. If the closure returns `false`, or panics, the element
3655+
/// remains in the vector and will not be yielded.
36563656
///
36573657
/// Only elements that fall in the provided range are considered for extraction, but any elements
36583658
/// after the range will still have to be moved if any element has been extracted.
@@ -3692,16 +3692,16 @@ impl<T, A: Allocator> Vec<T, A> {
36923692
/// But `extract_if` is easier to use. `extract_if` is also more efficient,
36933693
/// because it can backshift the elements of the array in bulk.
36943694
///
3695-
/// Note that `extract_if` also lets you mutate the elements passed to the filter closure,
3696-
/// regardless of whether you choose to keep or remove them.
3695+
/// The iterator also lets you mutate the value of each element in the
3696+
/// closure, regardless of whether you choose to keep or remove it.
36973697
///
36983698
/// # Panics
36993699
///
37003700
/// If `range` is out of bounds.
37013701
///
37023702
/// # Examples
37033703
///
3704-
/// Splitting an array into evens and odds, reusing the original allocation:
3704+
/// Splitting a vector into even and odd values, reusing the original vector:
37053705
///
37063706
/// ```
37073707
/// let mut numbers = vec![1, 2, 3, 4, 5, 6, 8, 9, 11, 13, 14, 15];

library/std/src/collections/hash/map.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -648,14 +648,14 @@ impl<K, V, S> HashMap<K, V, S> {
648648
Drain { base: self.base.drain() }
649649
}
650650

651-
/// Creates an iterator which uses a closure to determine if an element should be removed.
651+
/// Creates an iterator which uses a closure to determine if an element (key-value pair) should be removed.
652652
///
653-
/// If the closure returns true, the element is removed from the map and yielded.
654-
/// If the closure returns false, or panics, the element remains in the map and will not be
655-
/// yielded.
653+
/// If the closure returns `true`, the element is removed from the map and
654+
/// yielded. If the closure returns `false`, or panics, the element remains
655+
/// in the map and will not be yielded.
656656
///
657-
/// Note that `extract_if` lets you mutate every value in the filter closure, regardless of
658-
/// whether you choose to keep or remove it.
657+
/// The iterator also lets you mutate the value of each element in the
658+
/// closure, regardless of whether you choose to keep or remove it.
659659
///
660660
/// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating
661661
/// or the iteration short-circuits, then the remaining elements will be retained.

library/std/src/collections/hash/set.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ impl<T, S> HashSet<T, S> {
276276
Drain { base: self.base.drain() }
277277
}
278278

279-
/// Creates an iterator which uses a closure to determine if a value should be removed.
279+
/// Creates an iterator which uses a closure to determine if an element should be removed.
280280
///
281-
/// If the closure returns true, then the value is removed and yielded.
282-
/// If the closure returns false, the value will remain in the list and will not be yielded
283-
/// by the iterator.
281+
/// If the closure returns `true`, the element is removed from the set and
282+
/// yielded. If the closure returns `false`, or panics, the element remains
283+
/// in the set and will not be yielded.
284284
///
285285
/// If the returned `ExtractIf` is not exhausted, e.g. because it is dropped without iterating
286286
/// or the iteration short-circuits, then the remaining elements will be retained.

0 commit comments

Comments
 (0)