#[extendr]
pub fn {{ func_name }}({{ params_str }}) -> {{ return_type }} {
    use std::sync::Arc;
    use std::sync::Mutex;
    let {{ field_name }}_robj: Option<Robj> = {{ options_param }}.clone().as_list().and_then(|list| {
        list.iter().find(|(k, _)| *k == "{{ field_name }}").map(|(_, v)| v)
    }).filter(|v| !v.is_null() && !v.is_na());
    let {{ field_name }}_handle: Option<{{ handle_path }}> = {{ field_name }}_robj
        .map(|v| Arc::new(Mutex::new({{ struct_name }}::new(v))) as {{ handle_path }});
    let opts_local = crate::options::decode_options({{ options_param }})
        .map_err(|e| extendr_api::Error::Other(e))?;
    let mut opts: {{ core_import }}::{{ options_type }} = opts_local.into();
    opts.{{ field_name }} = {{ field_name }}_handle;
    {{ core_import }}::{{ func_name }}({{ call_args_str }})
        .map(crate::types::conversion_result_to_robj)
        .map_err(|e| extendr_api::Error::Other(e.to_string()))
}
