Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic UniffiRustCallStatus #2299

Open
Hinton opened this issue Nov 8, 2024 · 0 comments
Open

Generic UniffiRustCallStatus #2299

Hinton opened this issue Nov 8, 2024 · 0 comments

Comments

@Hinton
Copy link
Contributor

Hinton commented Nov 8, 2024

While working on #2265 I would like to use errors defined in external crates. Currently errors in UniFFI for kotlin are defined as with an ErrorHandler returning an instance of UniffiRustCallStatusErrorHandler. However since each crate currently define their own types for everything we have multiple implementations of UniffiRustCallStatusErrorHandler.

This is further complicated by the fact that uniffiRustCallWithError accepts a callback which uses UniffiRustCallStatus. UniffiRustCallStatus defines an error_buf as an instance of RustBuffer. As RustBuffer also have different implementations for each crate it's not easy to share these.

The most straightforward solution to this problem would be to make UniffiRustCallStatus, uniffiRustCallWithError and uniffiCheckCallStatus public. After which you could use uniffiRustCallWithError from the crate that defines the error (and also the RustBuffer implementation. However this diverges fairly significantly from the current design patterns used in UniFFI and feels like a sub-optimal approach.

Details

The generated code for function definitions would look something like this:

- fun uniffi_uniffi_ext_types_proc_macro_lib_fn_func_throw_external_error(uniffi_out_err: UniffiRustCallStatus, 
+ fun uniffi_uniffi_ext_types_proc_macro_lib_fn_func_throw_external_error(uniffi_out_err: uniffi.uniffi_one_ns.UniffiRustCallStatus, 
    ): Unit

    @Throws(UniffiOneException::class) fun `throwExternalError`()
        =
-        uniffiRustCallWithError(UniffiOneException) { _status ->
+        uniffi.uniffi_one_ns.uniffiRustCallWithError(UniffiOneException) { _status ->
    UniffiLib.INSTANCE.uniffi_uniffi_ext_types_proc_macro_lib_fn_func_throw_external_error(
        _status)

After raising the issue in matrix the ideal solution would most likely be to define the common types once, and be able to re-use them across all crates. This would ensure only a single implementation of RustBuffer exists, and potentially also only a single UniffiRustCallStatus removing the need for a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant