Expand description
§Basic JNI Bindings for Rust
This crate provides basic JNI bindings for Rust.
§Example
use typed_jni_core::{Arg, FieldID, JNIEnv, LocalRef, MethodID};
pub fn run_jni(env: &JNIEnv) {
unsafe {
let c_system = env.find_class(c"java/lang/System").unwrap();
let f_out: FieldID<true> = env.get_field_id(&c_system, c"out", c"Ljava/io/PrintStream;").unwrap();
let o_out: Option<LocalRef> = env.get_object_field(&c_system, f_out).unwrap();
let c_print_stream = env.get_object_class(o_out.as_ref().unwrap());
let m_println: MethodID<false> = env
.get_method_id(&c_print_stream, c"println", c"(Ljava/lang/String;)V")
.unwrap();
let s_hello = env.new_string("Hello, World!");
env.call_void_method(o_out.as_ref().unwrap(), m_println, [Arg::from(&s_hello)])
.unwrap();
}
}§Features
alloc: Enables the use ofalloccrate for dynamic memory allocation. (default)print-throwable: Enables the printing of throwable objects.
Modules§
Structs§
- Array
Elements Guard - Guard of an array elements.
- Attach
Error - FieldID
- Represents a field ID.
- Global
Ref - GlobalRef is a global reference to a Java object.
- JNIEnv
- A wrapper of raw JNI environment pointer.
- JavaVM
- JavaVM is a handle to the Java VM.
- Local
Ref - LocalRef is a local reference to a Java object.
- MethodID
- Represents a method ID.
- ModifiedUT
F8Str Guard - A guard that releases the modified UTF-8 string when dropped.
- Native
Function - Trampoline
Ref - TrampolineRef is a local reference to a Java object but only usable for native function implementation.
- Weak
Global Ref - GlobalWeakRef is a weak global reference to a Java object.
Enums§
- Arg
- Argument for a method call.
Traits§
- Ref
- A reference to a Java object.
- Strong
Ref - A strong reference to a Java object.
- WeakRef
- A weak reference to a Java object.