To provide the #[jni] annotations that work like this, you will need to use a compiler plugin. It would be an amazing tool, but so far it does not exist, as far as I know.
There are pieces of tools lying around that can be useful if you want to create a project that does this.
Plugins are currently unstable and do not work on non-night rust; you probably want to use syntex , which provides a stable interface for compiler plugins. You can also write a raw plugin (see here for the API for them), but most people will not be able to use it.
Here is rusty-cheddar , which generates c header files; You can take a look at this to see how it works. The author of this seems to be also working on a more general framework for creating bindings, but I don't know if he is active. You might be able to connect the cheddar output to something like JNAerator, but it probably won't create the most beautiful interfaces on the java side.
There are also rust-bindgen and corrode , which work in a different direction; they translate the headers c and arbitrary code c to rust, respectively. I do not know if this is really useful.
JNI-sys provides low-level JNI bindings; rust-on-mobile is a small project that uses it. Also see First Steps with Rust and Java , a blog post that shows some of the beginnings of getting things.
Lastly, a cbox that allows you to work with awkwardness with ownership and FFI.
James gilles
source share