#drain #vec #retain #no-std #drain-filter

no-std vec_mut_scan

Forward scan over a vector with mutation and item removal

5 releases (breaking)

0.5.0 Apr 16, 2023
0.4.0 Jan 17, 2021
0.3.0 Sep 8, 2020
0.2.0 Aug 24, 2020
0.1.0 May 16, 2019

#1279 in Algorithms

Download history 4345/week @ 2024-07-21 4539/week @ 2024-07-28 4576/week @ 2024-08-04 4247/week @ 2024-08-11 4253/week @ 2024-08-18 3446/week @ 2024-08-25 4236/week @ 2024-09-01 3351/week @ 2024-09-08 3823/week @ 2024-09-15 4919/week @ 2024-09-22 4623/week @ 2024-09-29 4482/week @ 2024-10-06 4102/week @ 2024-10-13 3672/week @ 2024-10-20 4551/week @ 2024-10-27 3723/week @ 2024-11-03

16,582 downloads per month
Used in 19 crates (via varisat)

0BSD license

42KB
566 lines

vec_mut_scan

github crates.io docs.rs

Forward scan over a vector with mutation and item removal.

Provides a VecMutScan wrapper for a Vec with an iterator like interface over which also allows mutation and removal of items. Items are kept in order and every item is moved at most once, even when items are removed. Dropping the VecMutScan mid-iteration keeps remaining items in the vector.

This can be seen as an extension of Vec's retain and drain. It is also very similar to the unstable drain_filter but slightly more flexible. Unlike drain_filter this specifies the drop behavior (to keep all following elements). It also doesn't require the filtering to be done within a closure, which gives additional flexibilty at the cost of not being able to implement the Iterator trait.

Also provides a VecGrowScan wrapper that extends VecMutScan to allow insertions during the iteration. This may require additional item moves and temporary storage, but still runs in linear time.

License

This software is available under the Zero-Clause BSD license, see COPYRIGHT for full licensing information and exceptions to this.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this software by you shall be licensed as defined in COPYRIGHT.

No runtime deps