try_map_vec

Function try_map_vec 

Source
pub fn try_map_vec<I, O, E>(
    predicate: fn(I) -> Result<O, E>,
) -> impl Fn(Vec<I>) -> Result<Vec<O>, E>
Expand description

Checks if all elements in the Vec satisfy the predicate (fallible ones accepted).

#[derive(Debug, Valust)]
struct All {
    #[trans(func(Vec<String> => try(try_map_vec(|x: String| x.parse::<i32>()))))]
    data: Vec<i32>
}

let all = Raw::<All> { data: vec!["1".to_owned(), "2".to_owned(), "3".to_owned()] };
let val = All::validate(all);
assert!(val.is_ok());
assert_eq!(vec![1, 2, 3], val.unwrap().data);