3 releases

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

#680 in Procedural macros

Download history 266/week @ 2023-12-18 317/week @ 2023-12-25 271/week @ 2024-01-01 259/week @ 2024-01-08 214/week @ 2024-01-15 458/week @ 2024-01-22 417/week @ 2024-01-29 427/week @ 2024-02-05 495/week @ 2024-02-12 737/week @ 2024-02-19 631/week @ 2024-02-26 757/week @ 2024-03-04 666/week @ 2024-03-11 691/week @ 2024-03-18 962/week @ 2024-03-25 833/week @ 2024-04-01

3,181 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.3–0.8MB
~19K SLoC