try_btree_map_values

Function try_btree_map_values 

Source
pub fn try_btree_map_values<K, V, E>(
    predicate: fn(&V) -> Result<bool, E>,
) -> impl Fn(&BTreeMap<K, V>) -> Result<bool, E>
Expand description

Checks if all values in the BTreeMap satisfy the predicate (fallible ones accepted).

#[derive(Debug, Valust)]
struct All {
    #[valid(func(try(try_btree_map_values(|v: &String| v.parse::<i32>().map(|u| u > 3)))))]
    data: BTreeMap<u8, String>
}

let all = Raw::<All> { data: vec![(1, "2".to_owned()), (2, "3".to_owned()), (3, "4".to_owned())].into_iter().collect() };
let val = All::validate(all);
assert!(val.is_err());
println!("{}", val.unwrap_err().full_stringify());