JniType

Trait JniType 

Source
pub unsafe trait JniType {
    // Required method
    fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R;
}
Expand description

JNI bindings rely on this type being accurate.

§Safety

unsafe: Passing the wrong type can cause unsoundness, since the code that interacts with JNI blindly trusts it’s correct.

Why the awkward callback style instead of returning &'static CStr? Arrays of arrays may need to dynamically construct their type strings, which would need to leak. Worse, we can’t easily intern those strings via lazy_static without running into:

error[E0401]: can't use generic parameters from outer function

Required Methods§

Source

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl JniType for &CStr

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for bool

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for ()

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jbyte

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jchar

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jdouble

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jfloat

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jint

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jlong

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Source§

impl JniType for jshort

Source§

fn static_with_jni_type<R>(callback: impl FnOnce(&CStr) -> R) -> R

Implementors§