pub fn rust_call<F, R>(out_status: &mut RustCallStatus, callback: F) -> Rwhere
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 returnOk(buf)
- The success type, must implement
FfiDefault
. Return::lower_return
returnsResult<>
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 allocatedRustBuffer
containing the error. The calling code is responsible for freeing theRustBuffer
FfiDefault::ffi_default()
is returned, although foreign code should ignore this value
- If the function panics:
out_status.code
will be set toCALL_PANIC
out_status.error_buf
will be set to a newly allocatedRustBuffer
containing a serialized error message. The calling code is responsible for freeing theRustBuffer
FfiDefault::ffi_default()
is returned, although foreign code should ignore this value