[−][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 unsafe fn from_ptr<'env>(ptr: *const JNIEnv) -> &'env Env
[src]
pub fn as_jni_env(&self) -> *mut JNIEnv
[src]
pub unsafe fn require_class(&self, class: &str) -> jclass
[src]
pub unsafe fn require_method(
&self,
class: jclass,
method: &str,
descriptor: &str
) -> jmethodID
[src]
&self,
class: jclass,
method: &str,
descriptor: &str
) -> jmethodID
pub unsafe fn require_static_method(
&self,
class: jclass,
method: &str,
descriptor: &str
) -> jmethodID
[src]
&self,
class: jclass,
method: &str,
descriptor: &str
) -> jmethodID
pub unsafe fn require_field(
&self,
class: jclass,
field: &str,
descriptor: &str
) -> jfieldID
[src]
&self,
class: jclass,
field: &str,
descriptor: &str
) -> jfieldID
pub unsafe fn require_static_field(
&self,
class: jclass,
field: &str,
descriptor: &str
) -> jfieldID
[src]
&self,
class: jclass,
field: &str,
descriptor: &str
) -> jfieldID
pub unsafe fn require_class_method(
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jmethodID)
[src]
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jmethodID)
pub unsafe fn require_class_static_method(
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jmethodID)
[src]
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jmethodID)
pub unsafe fn require_class_field(
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jfieldID)
[src]
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jfieldID)
pub unsafe fn require_class_static_field(
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jfieldID)
[src]
&self,
class: &str,
method: &str,
descriptor: &str
) -> (jclass, jfieldID)
pub unsafe fn new_object_a<'env, T: AsValidJObjectAndEnv>(
&'env self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<Local<'env, T>>
[src]
&'env self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<Local<'env, T>>
pub unsafe fn call_object_method_a<'env, T: AsValidJObjectAndEnv>(
&'env self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<Option<Local<'env, T>>>
[src]
&'env self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<Option<Local<'env, T>>>
pub unsafe fn call_boolean_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<bool>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<bool>
pub unsafe fn call_byte_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jbyte>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jbyte>
pub unsafe fn call_char_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jchar>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jchar>
pub unsafe fn call_short_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jshort>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jshort>
pub unsafe fn call_int_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jint>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jint>
pub unsafe fn call_long_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jlong>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jlong>
pub unsafe fn call_float_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jfloat>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jfloat>
pub unsafe fn call_double_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jdouble>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<jdouble>
pub unsafe fn call_void_method_a(
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<()>
[src]
&self,
this: jobject,
method: jmethodID,
args: *const jvalue
) -> Result<()>
pub unsafe fn call_static_object_method_a<'env, T: AsValidJObjectAndEnv>(
&'env self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<Option<Local<'env, T>>>
[src]
&'env self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<Option<Local<'env, T>>>
pub unsafe fn call_static_boolean_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<bool>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<bool>
pub unsafe fn call_static_byte_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jbyte>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jbyte>
pub unsafe fn call_static_char_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jchar>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jchar>
pub unsafe fn call_static_short_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jshort>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jshort>
pub unsafe fn call_static_int_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jint>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jint>
pub unsafe fn call_static_long_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jlong>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jlong>
pub unsafe fn call_static_float_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jfloat>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jfloat>
pub unsafe fn call_static_double_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jdouble>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<jdouble>
pub unsafe fn call_static_void_method_a(
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<()>
[src]
&self,
class: jclass,
method: jmethodID,
args: *const jvalue
) -> Result<()>
pub unsafe fn get_object_field<'env, T: AsValidJObjectAndEnv>(
&'env self,
this: jobject,
field: jfieldID
) -> Option<Local<'env, T>>
[src]
&'env self,
this: jobject,
field: jfieldID
) -> Option<Local<'env, T>>
pub unsafe fn get_boolean_field(&self, this: jobject, field: jfieldID) -> bool
[src]
pub unsafe fn get_byte_field(&self, this: jobject, field: jfieldID) -> jbyte
[src]
pub unsafe fn get_char_field(&self, this: jobject, field: jfieldID) -> jchar
[src]
pub unsafe fn get_short_field(&self, this: jobject, field: jfieldID) -> jshort
[src]
pub unsafe fn get_int_field(&self, this: jobject, field: jfieldID) -> jint
[src]
pub unsafe fn get_long_field(&self, this: jobject, field: jfieldID) -> jlong
[src]
pub unsafe fn get_float_field(&self, this: jobject, field: jfieldID) -> jfloat
[src]
pub unsafe fn get_double_field(&self, this: jobject, field: jfieldID) -> jdouble
[src]
pub unsafe fn set_object_field<'env, T: AsValidJObjectAndEnv>(
&'env self,
this: jobject,
field: jfieldID,
value: jobject
)
[src]
&'env self,
this: jobject,
field: jfieldID,
value: jobject
)
pub unsafe fn set_boolean_field(
&self,
this: jobject,
field: jfieldID,
value: bool
)
[src]
&self,
this: jobject,
field: jfieldID,
value: bool
)
pub unsafe fn set_byte_field(
&self,
this: jobject,
field: jfieldID,
value: jbyte
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jbyte
)
pub unsafe fn set_char_field(
&self,
this: jobject,
field: jfieldID,
value: jchar
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jchar
)
pub unsafe fn set_short_field(
&self,
this: jobject,
field: jfieldID,
value: jshort
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jshort
)
pub unsafe fn set_int_field(&self, this: jobject, field: jfieldID, value: jint)
[src]
pub unsafe fn set_long_field(
&self,
this: jobject,
field: jfieldID,
value: jlong
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jlong
)
pub unsafe fn set_float_field(
&self,
this: jobject,
field: jfieldID,
value: jfloat
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jfloat
)
pub unsafe fn set_double_field(
&self,
this: jobject,
field: jfieldID,
value: jdouble
)
[src]
&self,
this: jobject,
field: jfieldID,
value: jdouble
)
pub unsafe fn get_static_object_field<'env, T: AsValidJObjectAndEnv>(
&'env self,
class: jclass,
field: jfieldID
) -> Option<Local<'env, T>>
[src]
&'env self,
class: jclass,
field: jfieldID
) -> Option<Local<'env, T>>
pub unsafe fn get_static_boolean_field(
&self,
class: jclass,
field: jfieldID
) -> bool
[src]
&self,
class: jclass,
field: jfieldID
) -> bool
pub unsafe fn get_static_byte_field(
&self,
class: jclass,
field: jfieldID
) -> jbyte
[src]
&self,
class: jclass,
field: jfieldID
) -> jbyte
pub unsafe fn get_static_char_field(
&self,
class: jclass,
field: jfieldID
) -> jchar
[src]
&self,
class: jclass,
field: jfieldID
) -> jchar
pub unsafe fn get_static_short_field(
&self,
class: jclass,
field: jfieldID
) -> jshort
[src]
&self,
class: jclass,
field: jfieldID
) -> jshort
pub unsafe fn get_static_int_field(
&self,
class: jclass,
field: jfieldID
) -> jint
[src]
&self,
class: jclass,
field: jfieldID
) -> jint
pub unsafe fn get_static_long_field(
&self,
class: jclass,
field: jfieldID
) -> jlong
[src]
&self,
class: jclass,
field: jfieldID
) -> jlong
pub unsafe fn get_static_float_field(
&self,
class: jclass,
field: jfieldID
) -> jfloat
[src]
&self,
class: jclass,
field: jfieldID
) -> jfloat
pub unsafe fn get_static_double_field(
&self,
class: jclass,
field: jfieldID
) -> jdouble
[src]
&self,
class: jclass,
field: jfieldID
) -> jdouble
pub unsafe fn set_static_object_field<'env, T: AsValidJObjectAndEnv>(
&'env self,
class: jclass,
field: jfieldID,
value: jobject
)
[src]
&'env self,
class: jclass,
field: jfieldID,
value: jobject
)
pub unsafe fn set_static_boolean_field(
&self,
class: jclass,
field: jfieldID,
value: bool
)
[src]
&self,
class: jclass,
field: jfieldID,
value: bool
)
pub unsafe fn set_static_byte_field(
&self,
class: jclass,
field: jfieldID,
value: jbyte
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jbyte
)
pub unsafe fn set_static_char_field(
&self,
class: jclass,
field: jfieldID,
value: jchar
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jchar
)
pub unsafe fn set_static_short_field(
&self,
class: jclass,
field: jfieldID,
value: jshort
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jshort
)
pub unsafe fn set_static_int_field(
&self,
class: jclass,
field: jfieldID,
value: jint
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jint
)
pub unsafe fn set_static_long_field(
&self,
class: jclass,
field: jfieldID,
value: jlong
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jlong
)
pub unsafe fn set_static_float_field(
&self,
class: jclass,
field: jfieldID,
value: jfloat
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jfloat
)
pub unsafe fn set_static_double_field(
&self,
class: jclass,
field: jfieldID,
value: jdouble
)
[src]
&self,
class: jclass,
field: jfieldID,
value: jdouble
)
Auto Trait Implementations
impl Unpin for Env
impl !Sync for Env
impl !Send for Env
impl UnwindSafe for Env
impl RefUnwindSafe for Env
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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,