/// Configure the service via '{{ method_name }}'.
///
/// # Safety
/// - `owner` must be a valid pointer returned by `{{ new_fn_name }}()` and not yet freed.
/// - The same `owner` pointer is returned on success — the caller does **not**
/// need to swap the handle they hold. Returns `null` on failure (the original
/// handle is still valid in that case but should be inspected for usability).
#[unsafe(no_mangle)]
pub extern "C" fn {{ fn_name }}(
owner: AlefHandle{{ param_decls }}
) -> AlefHandle {
catch_ffi_panic(0, || {
if owner == 0 {
return 0;
}
{{ pre_call_body }} // SAFETY: owner was allocated by _new() and is valid until freed.
// Take the inner box out, transform it, and put the result back. The opaque
// shell stays at the same address so the caller's handle remains valid.
match with_handle_mut::<{{ opaque_name }}, _>(owner, |service| {
let inner = match service.inner.take() {
Some(boxed) => *boxed,
None => return false,
};
service.inner = Some(Box::new(inner.{{ method_name }}({{ call_args }})));
true
}) {
Ok(true) => owner,
Ok(false) => 0,
Err(error) => { set_handle_error(&error); 0 }
}
})
}