Function malachite_base::options::option_from_str
source · pub fn option_from_str<T: FromStr>(src: &str) -> Option<Option<T>>
Expand description
Converts a string to an Option<T>
, where T
implements FromStr
.
If the string does not represent a valid Option<T>
, None
is returned.
If T
does not implement FromStr
, try using option_from_str_custom
instead.
§Examples
use malachite_base::options::option_from_str;
assert_eq!(option_from_str::<bool>("Some(false)"), Some(Some(false)));
assert_eq!(option_from_str::<u32>("Some(5)"), Some(Some(5)));
assert_eq!(option_from_str::<u32>("None"), Some(None));
assert_eq!(option_from_str::<u32>("Some(hi)"), None);
assert_eq!(option_from_str::<bool>("abc"), None);