Function uniffi::ffi::rustcalls::call_with_result [−][src]
pub fn call_with_result<F, R>(out_status: &mut RustCallStatus, callback: F) -> R where
F: UnwindSafe + FnOnce() -> Result<R, RustBuffer>,
R: FfiDefault,
Expand description
Wrap a rust function call that returns a Result<_, RustBuffer>
callback
is responsible for making the call to the Rust function.
-
callback
must convert any return value into a type that implementsIntoFfi
-
callback
must convert anyError
the into aRustBuffer
to be returned over the FFI -
(Both of these are typically handled with
FfiConverter::lower()
) -
If the function returns an
Ok
value it will be unwrapped and returned -
If the function returns an
Err
:out_status.code
will be set toCALL_ERROR
out_status.error_buf
will be set to a newly allocatedRustBuffer
containing the error. The calling code is responsible for freeing theRustBuffer
- the return value is undefined
-
If the function panics:
out_status.code
will be set toCALL_PANIC
- the return value is undefined