ejni

Crates.ioejni
lib.rsejni
version0.1.0
sourcesrc
created_at2021-08-09 21:20:13.159501
updated_at2022-04-05 12:35:02.152452
descriptionLibrary to make working with JNI more pleasant
homepagehttps://github.com/TheDutchMC/eJNI
repositoryhttps://github.com/TheDutchMC/eJNI
max_upload_size
id433986
size135,249
Tobias de Bruijn (TobiasDeBruijn)

documentation

README

eJNI

eJNI is a Rust crate to make working with Java's JNI less painful by providing abstractions.

eJNI provides abstractions for often-used classes from the Java standard library, like Map and List. Besides this eJNI also provides easy ways to work with Java's primitives and their object counterparts (e.g int and Integer).

API stability

eJNI is a young library, and it's API is likely to change. The code in the library is fully tested though.

Examples

ArrayList

The following example shows how to create an ArrayList<String>, fill it with 10 Strings, and return it to Java.

use ejni::{List, Class, Object, JavaString};
use jni::sys::jobject;

#[no_mangle]
pub fn Java_MyClass_doNative(env: JNIEnv<'_>, _: JClass) -> jobject {
    // Create a new java.util.ArrayList containing java.lang.String's
    let list = List::arraylist(&env, Class::String(&env).unwrap()).unwrap();

    // Add 10 Strings to the List
    for i in 0..10 {
        let string = JavaString::from_rust(&env, format!("Iteration {}", i)).unwrap();
        list.add(&env, string).unwrap();
    }

    list.into()
}
Commit count: 17

cargo fmt