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

JNI bindings rely on this type being accurate.

unsafe: static_with_jni_type must pass a string terminated by ‘\0’. Failing to do so is a soundness bug, as the string is passed directly to JNI as a raw pointer! Additionally, passing the wrong type may be a soundness bug as although the Android JVM will simply panic and abort, I’ve no idea if that’s a guarantee or not.

Why the awkward callback style instead of returning &'static str? 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(&str) -> R) -> R

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl JniType for &str

source§

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

source§

impl JniType for bool

source§

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

source§

impl JniType for ()

source§

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

source§

impl JniType for jbyte

source§

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

source§

impl JniType for jchar

source§

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

source§

impl JniType for jdouble

source§

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

source§

impl JniType for jfloat

source§

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

source§

impl JniType for jint

source§

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

source§

impl JniType for jlong

source§

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

source§

impl JniType for jshort

source§

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

Implementors§