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 implements IntoFfi

  • callback must convert any Error the into a RustBuffer 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 to CALL_ERROR
    • out_status.error_buf will be set to a newly allocated RustBuffer containing the error. The calling code is responsible for freeing the RustBuffer
    • the return value is undefined
  • If the function panics:

    • out_status.code will be set to CALL_PANIC
    • the return value is undefined