collect_vec_with_max_len_simple_validation/
collect_vec_with_max_len_simple_validation.rs

1extern crate validiter;
2use validiter::AtMost;
3
4struct TooMany(usize, i32);
5
6fn main() {
7    let collection_failure = (0..10)
8        .map(|i| Ok(i))
9        .at_most(7, |err_index, i| TooMany(err_index, i))
10        .collect::<Result<Vec<_>, _>>();
11    match collection_failure {
12        Ok(_vector) => unreachable!(),
13        Err(TooMany(i, v)) => print!(
14            "{v} is the first value obtained after reaching limit, at index {i} of the iteration"
15        ),
16    }
17}