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

Converts a string to an Option<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 the FromStr implementation on T, you can use option_from_str instead.

Examples

use malachite_base::options::{option_from_str, option_from_str_custom};
use malachite_base::orderings::ordering_from_str;
use std::cmp::Ordering;

assert_eq!(
    option_from_str_custom::<Ordering>(&ordering_from_str, "Some(Less)"),
    Some(Some(Ordering::Less))
);
assert_eq!(
    option_from_str_custom::<Option<bool>>(&option_from_str, "Some(Some(false))"),
    Some(Some(Some(false)))
);
assert_eq!(
    option_from_str_custom::<Ordering>(&ordering_from_str, "Some(hi)"),
    None
);
assert_eq!(
    option_from_str_custom::<Ordering>(&ordering_from_str, "abc"),
    None
);