#retain #give #no-std #mutable #predicate #borrow #reference

deprecated no-std retain_mut

Provide retain_mut method that has the same functionality as retain but gives mutable borrow to the predicate

10 releases

Uses old Rust 2015

0.1.9 May 20, 2022
0.1.7 Feb 25, 2022
0.1.5 Dec 3, 2021
0.1.4 Sep 26, 2021
0.1.0 Nov 28, 2018

#8 in #retain

Download history 150804/week @ 2024-07-19 154534/week @ 2024-07-26 142630/week @ 2024-08-02 166531/week @ 2024-08-09 190487/week @ 2024-08-16 177792/week @ 2024-08-23 159735/week @ 2024-08-30 187081/week @ 2024-09-06 163458/week @ 2024-09-13 196552/week @ 2024-09-20 174304/week @ 2024-09-27 207485/week @ 2024-10-04 184645/week @ 2024-10-11 208212/week @ 2024-10-18 232499/week @ 2024-10-25 195635/week @ 2024-11-01

864,579 downloads per month
Used in 315 crates (4 directly)

MIT license

11KB
111 lines

RetainMut

This crate has been deprecated. Rust 1.61 stabilized retain_mut for Vec and VecDeque, so you can use them directly. This crate is no longer maintained.

This crate provides trait RetainMut which provides retain_mut method for Vec and VecDeque.

retain_mut is basically the same as retain except that it gives mutable reference of items to the predicate function.

Since there is no reason retain couldn't have been designed this way, this crate basically just copies the code from std with minor changes to hand out mutable reference. The code these impls are based on can be found in code comments of this crate.

This was probably a historical mistake in Rust library, that retain should do this at the very beginning. See rust-lang/rust#25477.

From Rust 1.58, an unstable retain_mut method has been added to the std, see rust-lang/rust#90829. Once it gets stabilized, you can simply remove this crate.

Examples

Vec

let mut vec = vec![1, 2, 3, 4];
vec.retain_mut(|x| { *x *= 3; *x % 2 == 0 });
assert_eq!(vec, [6, 12]);

VecDeque

let mut deque = VecDeque::from(vec![1, 2, 3, 4]);
deque.retain_mut(|x| { *x *= 3; *x % 2 == 0 });
assert_eq!(deque, [6, 12]);

No runtime deps