Function uniffi::ffi::rust_call

source ·
pub fn rust_call<F, R>(out_status: &mut RustCallStatus, callback: F) -> R
where F: UnwindSafe + FnOnce() -> Result<R, RustBuffer>, R: FfiDefault,
Expand description

Handle a scaffolding calls

callback is responsible for making the actual Rust call and returning a special result type:

  • For successful calls, return Ok(value)
  • For errors that should be translated into thrown exceptions in the foreign code, serialize the error into a RustBuffer, then return Ok(buf)
  • The success type, must implement FfiDefault.
  • Return::lower_return returns Result<> types that meet the above criteria>
  • If the function returns a Ok value it will be unwrapped and returned
  • If the function returns a Err value:
    • out_status.code will be set to RustCallStatusCode::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
    • FfiDefault::ffi_default() is returned, although foreign code should ignore this value
  • If the function panics:
    • out_status.code will be set to CALL_PANIC
    • out_status.error_buf will be set to a newly allocated RustBuffer containing a serialized error message. The calling code is responsible for freeing the RustBuffer
    • FfiDefault::ffi_default() is returned, although foreign code should ignore this value