rust/library/alloc/src/vec
Trevor Gross c44e1d65f3
Rollup merge of #135734 - nk9:extract_if-doc-equivalent, r=tgross35
Correct `extract_if` sample equivalent.

Tracking issue: https://github.com/rust-lang/rust/issues/43244

Original PR: #133265

The sample code marked as equivalent in the doc comment isn't currently equivalent. Given the same predicate and range, if your vector were `[1, 2, 3, 3, 3, 3, 3, 3, 4, 5, 6]`, then all of the 3s would be removed. `i` is only incremented when an element is dropped, but `range.end` is unchanged, so the items shift down. I got very confused when reading the docs and trying to square this sample code with the explanation of how the function works.

Fortunately, the real `extract_if()` does not have this problem. I've added an `end` variable to align the behavior. I've also taken the opportunity to simplify the predicate, which now just matches odd numbers, and to pad out the vec of numbers to line up the zero-indexed range with the integers in the vec.

r? the8472
2025-05-05 00:20:57 -04:00
..
cow.rs Add #[track_caller] to allocating methods of Vec & VecDeque 2024-09-20 01:20:10 +03:00
drain.rs rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
extract_if.rs replace version placeholder 2025-04-09 12:29:59 +01:00
in_place_collect.rs library: Use size_of from the prelude instead of imported 2025-03-06 20:20:38 -08:00
in_place_drop.rs rename sub_ptr 😅 2025-02-23 23:11:00 +07:00
into_iter.rs Rename sub_ptr to offset_from_unsigned in docs 2025-04-28 13:58:27 +02:00
is_zero.rs alloc: remove unsound IsZero for raw pointers 2025-01-10 18:48:48 +01:00
mod.rs Rollup merge of #135734 - nk9:extract_if-doc-equivalent, r=tgross35 2025-05-05 00:20:57 -04:00
partial_eq.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
set_len_on_drop.rs Tune RepeatWith::try_fold and Take::for_each and Vec::extend_trusted 2022-11-24 19:14:19 -08:00
spec_extend.rs Add #[track_caller] to allocating methods of Vec & VecDeque 2024-09-20 01:20:10 +03:00
spec_from_elem.rs Add #[track_caller] to allocating methods of Vec & VecDeque 2024-09-20 01:20:10 +03:00
spec_from_iter.rs Add #[track_caller] to allocating methods of Vec & VecDeque 2024-09-20 01:20:10 +03:00
spec_from_iter_nested.rs Add #[track_caller] to allocating methods of Vec & VecDeque 2024-09-20 01:20:10 +03:00
splice.rs Rename sub_ptr to offset_from_unsigned in docs 2025-04-28 13:58:27 +02:00