try_btree_map

Function try_btree_map 

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

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

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

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