1
Fork 0

Rollup merge of #97187 - ajtribick:patch-1, r=thomcc

Reverse condition in Vec::retain_mut doctest

I find that the doctest for `Vec::retain_mut` is easier to read and understand when the `if` block corresponds to the path that returns `true` and the `else` block returns `false`. Having the `if` block be the `false` path led me to stare at the example for somewhat longer than I probably had to.
This commit is contained in:
Matthias Krüger 2022-05-20 19:54:40 +02:00 committed by GitHub
commit daf4f34fe3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1470,11 +1470,11 @@ impl<T, A: Allocator> Vec<T, A> {
///
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.retain_mut(|x| if *x > 3 {
/// false
/// } else {
/// vec.retain_mut(|x| if *x <= 3 {
/// *x += 1;
/// true
/// } else {
/// false
/// });
/// assert_eq!(vec, [2, 3, 4]);
/// ```