#benchmark #become #iterator #false #predicate #drain #stops

drain-while

A draining iterator which stops when a predicate becomes false

1 unstable release

Uses old Rust 2015

0.1.0 Jun 28, 2017

#15 in #drain

23 downloads per month
Used in 3 crates (via opmap)

MIT/Apache

7KB

A draining Iterator which stops when a predicate becomes false.

use drain_while::*;

let mut original = vec![1,2,3,4,5];
let mut matching = vec![];

for x in original.drain_while(|x| *x < 3) {
    matching.push(x);
}

assert_eq!(matching, vec![1,2]);
assert_eq!(original, vec![3,4,5]);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

This library provides a draining Iterator which stops when a predicate becomes false.

use drain_while::*;

let mut original = vec![1,2,3,4,5];
let mut matching = vec![];

for x in original.drain_while(|x| *x < 3) {
matching.push(x);
}

assert_eq!(matching, vec![1,2]);
assert_eq!(original, vec![3,4,5]);

See the documentation for drain_while() for more.

No runtime deps