[−][src]Struct jni_glue::Env
FFI: Use &Env instead of *const JNIEnv. This represents a per-thread Java exection environment.
A "safe" alternative to jni_sys::JNIEnv raw pointers, with the following caveats:
-
A null env will result in undefined behavior. Java should not be invoking your native functions with a null *mut JNIEnv, however, so I don't believe this is a problem in practice unless you've bindgened the C header definitions elsewhere, calling them (requiring
unsafe
), and passing null pointers (generally UB for JNI functions anyways, so can be seen as a caller soundness issue.) -
Allowing the underlying JNIEnv to be modified is undefined behavior. I don't believe the JNI libraries modify the JNIEnv, so as long as you're not accepting a *mut JNIEnv elsewhere, using unsafe to dereference it, and mucking with the methods on it yourself, I believe this "should" be fine.
Example
MainActivity.java
package com.maulingmonkey.example;
public class MainActivity extends androidx.appcompat.app.AppCompatActivity {
@Override
public native boolean dispatchKeyEvent(android.view.KeyEvent keyEvent);
// ...
}
main_activity.rs
use jni_sys::{jboolean, jobject, JNI_TRUE}; // TODO: Replace with safer equivalent use jni_glue::Env; #[no_mangle] pub extern "system" fn Java_com_maulingmonkey_example_MainActivity_dispatchKeyEvent<'env>( _env: &Env, _this: jobject, // TODO: Replace with safer equivalent _key_event: jobject // TODO: Replace with safer equivalent ) -> jboolean { // ... JNI_TRUE }
Methods
impl Env
[src]
pub fn as_jni_env(&self) -> *mut JNIEnv
[src]
Auto Trait Implementations
impl !Sync for Env
impl Unpin for Env
impl !Send for Env
impl UnwindSafe for Env
impl RefUnwindSafe for Env
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,