    fn {{ method_name }}({{ sig }}) -> {{ ret_ty }} {
{%- for arg in args %}
        let {{ arg.binding }} = {{ arg.owned_expr }};
{%- endfor %}
        let result = visitor_send_and_wait(self, "{{ handle_name }}", |env| {
            let {% if args %}mut {% endif %}args_map = rustler::Term::map_new(env);
{%- for arg in args %}
            args_map = args_map.map_put("{{ arg.key }}".encode(env), {{ arg.binding }}.encode(env)).expect("map_put");
{%- endfor %}
            args_map
        });
        match result {
            None => {{ default_result_expr }},
            Some(s) => {
                match s.as_str() {
{%- for variant in unit_result_variants %}
                    "{{ variant.wire_name }}" => {{ ret_ty }}::{{ variant.name }},
{%- endfor %}
                    _ => {{ unknown_string_result_expr }},
                }
            }
        }
    }
