#jni #java #jvm #android #ndk

macro jni_fn

JNI-compatible method signature generator

3 releases

0.1.2 Aug 14, 2023
0.1.1 Aug 14, 2023
0.1.0 Nov 8, 2021

#210 in Procedural macros

Download history 333/week @ 2023-11-03 417/week @ 2023-11-10 263/week @ 2023-11-17 230/week @ 2023-11-24 236/week @ 2023-12-01 272/week @ 2023-12-08 397/week @ 2023-12-15 321/week @ 2023-12-22 312/week @ 2023-12-29 395/week @ 2024-01-05 267/week @ 2024-01-12 376/week @ 2024-01-19 525/week @ 2024-01-26 476/week @ 2024-02-02 431/week @ 2024-02-09 626/week @ 2024-02-16

2,124 downloads per month
Used in 6 crates (4 directly)

MIT/Apache

17KB
298 lines

jni_fn

crates.io Docs License

jni_fn is a JNI-compatible method signature generator for Rust libraries.

This crate was designed for use with the jni crate, which exposes JNI-compatible type bindings. Although it's possible to use jni without jni_fn, the procedural macro defined here will make it easier to write the method signatures correctly.

How to use

Check the jni repo to get started with your first Rust JNI bindings.

Note the function signatures in the jni example project, which must be transcribed 100% correctly to avoid runtime panics in your JVM project:

#[no_mangle]
pub extern "system" fn Java_HelloWorld_hello(
    // ...

Instead, jni_fn can automatically generate the correct function signature based on the package name (HelloWorld) and function name (hello):

use jni_fn::jni_fn;

#[jni_fn("HelloWorld")]
pub fn hello(
    // ...

jni_fn is especially useful in more complicated examples - you don't want to figure this out manually! With jni_fn, all you need is:

#[jni_fn("org.signal.client.internal.Native")]
pub unsafe fn IdentityKeyPair_Deserialize(
    // ...

Visit the docs for more instructions and examples.

Dependencies

~0.4–0.8MB
~19K SLoC