validiter 0.3.0

Iterator adapters for validating iterations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
extern crate validiter;
use validiter::AtMost;

struct TooMany(usize, i32);

fn main() {
    let collection_failure = (0..10)
        .map(|i| Ok(i))
        .at_most(7, |err_index, i| TooMany(err_index, i))
        .collect::<Result<Vec<_>, _>>();
    match collection_failure {
        Ok(_vector) => unreachable!(),
        Err(TooMany(i, v)) => print!(
            "{v} is the first value obtained after reaching limit, at index {i} of the iteration"
        ),
    }
}