I want to call Rust code from Java / Android, and I've found 3 variants to do so:
JNI looks good and powerful enough, but you have to write too much code by hand.
JNA, if not taking into consideration that it crashes on my machine, requires writing Rust struct data type description in Java by hand, the same problem with JNR FFI.
So I wonder how difficult will be generate JNI code
for traits
and struct
with macros or a compiler plugin?
This compiler should match traits implementations for concrete struct,
and also struct
#[JNI]
struct Foo {
a: i32,
}
trait Boo {
fn f(&self, b: f64) -> f64;
}
#[JNI]
impl Boo for Foo {
fn f(&self, b: f64) -> f64 {
0f64
}
}
and create Java classes for struct and Java classes with native
functions, plus generate pub
no_mangle
functions that wrap traits functions.