Function get_optional_parsed

Source
pub fn get_optional_parsed<T, F>(
    dict: &Bound<'_, PyDict>,
    key: &str,
    parser: F,
) -> PyResult<Option<T>>
where F: FnOnce(String) -> Result<T, String>,
Expand description

Helper function to get an optional value, parse it with a closure, and handle parse errors.

§Returns

Returns Some(parsed_value) if the key exists and parsing succeeds, None if the key is missing or if the value is Python None, or a PyErr if extraction or parsing fails.

§Errors

Returns PyErr if value extraction or parsing fails (but not if the key is missing or value is None).