in uniffi_bindgen/src/bindings/python/templates/CallbackInterfaceImpl.py [0:0]
def {{ meth.name() }}(
{%- for arg in ffi_callback.arguments() %}
{{ arg.name() }},
{%- endfor -%}
{%- if ffi_callback.has_rust_call_status_arg() %}
uniffi_call_status_ptr,
{%- endif %}
):
uniffi_obj = {{ ffi_converter_name }}._handle_map.get(uniffi_handle)
def make_call():
args = ({% for arg in meth.arguments() %}{{ arg|lift_fn }}({{ arg.name() }}), {% endfor %})
method = uniffi_obj.{{ meth.name() }}
return method(*args)
{% if !meth.is_async() %}
{%- match meth.return_type() %}
{%- when Some(return_type) %}
def write_return_value(v):
uniffi_out_return[0] = {{ return_type|lower_fn }}(v)
{%- when None %}
write_return_value = lambda v: None
{%- endmatch %}
{%- match meth.throws_type() %}
{%- when None %}
_uniffi_trait_interface_call(
uniffi_call_status_ptr.contents,
make_call,
write_return_value,
)
{%- when Some(error) %}
_uniffi_trait_interface_call_with_error(
uniffi_call_status_ptr.contents,
make_call,
write_return_value,
{{ error|type_name }},
{{ error|lower_fn }},
)
{%- endmatch %}
{%- else %}
def handle_success(return_value):
uniffi_future_callback(
uniffi_callback_data,
{{ meth.foreign_future_ffi_result_struct().name()|ffi_struct_name }}(
{%- if let Some(return_type) = meth.return_type() %}
{{ return_type|lower_fn }}(return_value),
{%- endif %}
_UniffiRustCallStatus.default()
)
)
def handle_error(status_code, rust_buffer):
uniffi_future_callback(
uniffi_callback_data,
{{ meth.foreign_future_ffi_result_struct().name()|ffi_struct_name }}(
{%- match meth.return_type() %}
{%- when Some(return_type) %}
{{ meth.return_type().map(FfiType::from)|ffi_default_value(ci) }},
{%- when None %}
{%- endmatch %}
_UniffiRustCallStatus(status_code, rust_buffer),
)
)
{%- match meth.throws_type() %}
{%- when None %}
uniffi_out_return[0] = _uniffi_trait_interface_call_async(make_call, handle_success, handle_error)
{%- when Some(error) %}
uniffi_out_return[0] = _uniffi_trait_interface_call_async_with_error(make_call, handle_success, handle_error, {{ error|type_name }}, {{ error|lower_fn }})
{%- endmatch %}
{%- endif %}