Crates.io | jnino |
lib.rs | jnino |
version | 0.1.1 |
source | src |
created_at | 2021-09-07 18:03:22.017155 |
updated_at | 2021-09-12 19:04:30.701993 |
description | Java Native Interface to rust Native Objects |
homepage | |
repository | https://github.com/tiberiuscn/jnino |
max_upload_size | |
id | 448165 |
size | 4,831 |
This project allows you to use rust objects like part of jvm objects.
add native constructor with Long return and private Long property
implement AutoCloseable as native method
add finalizer
add native methods
class Sample extends AutoCloseable {
@native private def nnew(): Long
@native def close: Unit
@native def test: Unit
private val ptr = nnew()
override def finalize = close
}
#[derive(JFace)]
pub struct Sample { … }
use throw(JNIEnv, default_function) for converting rust Jr<> (Result<, Box
use JFace::jni() for converting to raw heap pointer
provide native constructor to JNI
#[no_mangle]
pub extern "system" fn Java_package_Sample_nnew(
jenv: JNIEnv,
_jclass: JClass,
) -> *mut Sample {
Sample::new().jni().throw(jenv, null_mut)
}
use unit for Result<(), _>::throw() or hide for Result<T, _>::throw for unneeded T
use JFace::mut_raw and map/and_then for native methods
#[no_mangle]
pub extern "system" fn Java_org_apqm_jni_Sample_test(
jenv: JNIEnv,
jclass: JClass,
) {
Sample::mut_raw(&jenv, jclass).map(|it| {
todo!()
}).throw(jenv, unit);
}
#[no_mangle]
pub extern "system" fn Java_org_apqm_jni_Sample_close(
jenv: JNIEnv,
jclass: JClass,
) {
Sample::box_raw(&jenv, jclass).map(hide).throw(jenv, unit)
}
Licensed under either of