vec_remove_if

Crates.iovec_remove_if
lib.rsvec_remove_if
version1.0.0
sourcesrc
created_at2022-07-23 19:10:44.746057
updated_at2022-07-23 19:10:44.746057
descriptionExtract elements from a vector based on supplied criteria
homepage
repositoryhttps://gitlab.com/SnSDev/vec_remove_if
max_upload_size
id631683
size6,410
Matthew "Juniper" Barlett (KE0PVD) (emeraldinspirations)

documentation

README

vec_remove_if

Extract elements from a vector based on supplied criteria

Project by SnS Development

Problem

Need to filter some elements out of an existing Vector through a mutable borrow

Solution

A trait implemented on Vec<T> with 2 functions remove_if and swap_remove_if that iterate over elements, runs a supplied closure, and removes elements where the closure returns [true].

Example

use vec_remove_if::VecRemoveIf;
let mut v = vec![1, 12, 3, 14, 5, 16, 7, 18];

assert_eq!(
    vec![12, 14, 16, 18],
    v.remove_if(|e| e > &10)
);
assert_eq!(
    vec![1, 3, 5, 7],
    v
);

License: MIT

Commit count: 1

cargo fmt