Crate typed_jni_core

Crate typed_jni_core 

Source
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 of alloc crate for dynamic memory allocation. (default)
  • print-throwable: Enables the printing of throwable objects.

Modules§

sys

Structs§

ArrayElementsGuard
Guard of an array elements.
AttachError
FieldID
Represents a field ID.
GlobalRef
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.
LocalRef
LocalRef is a local reference to a Java object.
MethodID
Represents a method ID.
ModifiedUTF8StrGuard
A guard that releases the modified UTF-8 string when dropped.
NativeFunction
TrampolineRef
TrampolineRef is a local reference to a Java object but only usable for native function implementation.
WeakGlobalRef
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.
StrongRef
A strong reference to a Java object.
WeakRef
A weak reference to a Java object.

Type Aliases§

AttachHook