mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.83k stars 231 forks source link

Add support for reference arguments in the rust code #4

Closed rfk closed 4 years ago

rfk commented 4 years ago

Currently, every rust function exposed over the FFI is expected to take ownership of its arguments. This is most obvious in the existing "sprites" example, where the code for translate has to be declared as:

Which means that when the move_to method of the Sprite class calls it, it has to pass in a clone:

Making this more egonomic could be a good opportunity for somone new to the codebase to get familiar with it. The challenge would be to update the sprites example so that the translate function is declared as:

And the .clone() mentioned above can be removed.

In order to achieve this I think you would need to:

┆Issue is synchronized with this Jira Task

linabutler commented 4 years ago

This isn't a Nimbus blocker, right? The fanciest data type in @tarikeshaq's proposed IDL is ApplicationContext, and that's a dictionary so it has value semantics, but just wanted to double-check!

savi2w commented 4 years ago

I'll try to make this issue 😉

rfk commented 4 years ago

Great, thanks for diving in!

Make sure the sprites example still runs and outputs sensible result (in lieu of actual tests, which are forthcoming).

I should note, since I wrote the above, the examples have evolved into actual (if pretty minimal) tests, which will run here in CI or can be executed using cargo test if you have all the various command-line tools for the different target languages installed.