pub fn vec_from_str<T: FromStr>(src: &str) -> Option<Vec<T>>
Expand description

Converts a string to an Vec<T>, where T implements FromStr.

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

If T does not implement FromStr, try using vec_from_str_custom 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::nevers::Never;
use malachite_base::vecs::vec_from_str;

assert_eq!(vec_from_str::<Never>("[]"), Some(vec![]));
assert_eq!(vec_from_str("[5, 6, 7]"), Some(vec![5, 6, 7]));
assert_eq!(vec_from_str("[false, false, true]"), Some(vec![false, false, true]));
assert_eq!(vec_from_str::<bool>("[false, false, true"), None);