Type Definition uniffi::ForeignCallback

source ·
pub type ForeignCallback = unsafe extern "C" fn(_: u64, _: u32, _: RustBuffer, _: *mut RustBuffer) -> i32;
Expand description

ForeignCallback is the Rust representation of a foreign language function. It is the basis for all callbacks interfaces. It is registered exactly once per callback interface, at library start up time. Calling this method is only done by generated objects which mirror callback interfaces objects in the foreign language.

  • The handle is the key into a handle map on the other side of the FFI used to look up the foreign language object that implements the callback interface/trait.
  • The method selector specifies the method that will be called on the object, by looking it up in a list of methods from the IDL. The index is 1 indexed. Note that the list of methods is generated by at uniffi from the IDL and used in all bindings: so we can rely on the method list being stable within the same run of uniffi.
  • args is a serialized buffer of arguments to the function. UniFFI will deserialize it before passing individual arguments to the user’s callback.
  • buf_ptr is a pointer to where the resulting buffer will be written. UniFFI will allocate a buffer to write the result into.
  • A callback returns:
    • -2 An error occurred that was serialized to buf_ptr
    • -1 An unexpected error occurred
    • 0 is a deprecated way to signal that if the call succeeded, but did not modify buf_ptr
    • 1 If the call succeeded. For non-void functions the return value should be serialized to buf_ptr. Note: The output buffer might still contain 0 bytes of data.