pub fn vec_from_str_custom<T>(
    f: &dyn Fn(&str) -> Option<T>,
    src: &str
) -> Option<Vec<T>>
Expand description

Converts a string to an Vec<T>, given a function to parse a string into a T.

If the string does not represent a valid Option<T>, None is returned.

If f just uses FromStr::from_str, you can use vec_from_str instead.

Substrings representing Ts may contain commas. Sometimes this may lead to ambiguities: for example, the two Vec<&str>s vec!["a, b"] and vec!["a", "b"] both have the string representation "[a, b]". The parser is greedy, so it will interpet this string as vec!["a", "b"].

Examples

use malachite_base::options::option_from_str;
use malachite_base::orderings::ordering_from_str;
use malachite_base::vecs::{vec_from_str, vec_from_str_custom};
use std::cmp::Ordering;

assert_eq!(
    vec_from_str_custom(&ordering_from_str, "[Less, Greater]"),
    Some(vec![Ordering::Less, Ordering::Greater]),
);
assert_eq!(
    vec_from_str_custom(&option_from_str, "[Some(false), None]"),
    Some(vec![Some(false), None]),
);
assert_eq!(
    vec_from_str_custom(&vec_from_str, "[[], [3], [2, 5]]"),
    Some(vec![vec![], vec![3], vec![2, 5]]),
);
assert_eq!(
    vec_from_str_custom(&option_from_str::<bool>, "[Some(fals), None]"),
    None
);