Crates.io | ejni |
lib.rs | ejni |
version | 0.1.0 |
source | src |
created_at | 2021-08-09 21:20:13.159501 |
updated_at | 2022-04-05 12:35:02.152452 |
description | Library to make working with JNI more pleasant |
homepage | https://github.com/TheDutchMC/eJNI |
repository | https://github.com/TheDutchMC/eJNI |
max_upload_size | |
id | 433986 |
size | 135,249 |
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
).
eJNI is a young library, and it's API is likely to change. The code in the library is fully tested though.
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()
}