Skip to main content

Env

Struct Env 

Source
#[repr(transparent)]
pub struct Env(pub *mut *const [*const c_void; 234]);
Expand description

A JNI environment pointer, valid only on the thread that produced it.

repr(transparent) because the VM passes this as a bare JNIEnv* to every native method — it must have exactly a pointer’s layout.

Tuple Fields§

§0: *mut *const [*const c_void; 234]

Implementations§

Source§

impl Env

Source

pub fn version(&self) -> i32

Source

pub fn find_class(&self, name: &str) -> Option<JClass>

FindClass, with an internal name like android/bluetooth/BluetoothAdapter.

Returns a local reference; promote it with Env::new_global_ref to keep it past the current frame.

Source

pub fn get_object_class(&self, object: JObject) -> JClass

Source

pub fn method_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JMethodId>

Source

pub fn static_method_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JMethodId>

Source

pub fn static_field_id( &self, class: JClass, name: &str, signature: &str, ) -> Option<JFieldId>

Source

pub fn static_object_field(&self, class: JClass, field: JFieldId) -> JObject

Source

pub fn static_int_field(&self, class: JClass, field: JFieldId) -> i32

Source

pub fn call_object( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> JObject

Source

pub fn call_bool( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> bool

Source

pub fn call_int( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> i32

Source

pub fn call_long( &self, object: JObject, method: JMethodId, args: &[JValue], ) -> i64

Source

pub fn call_void(&self, object: JObject, method: JMethodId, args: &[JValue])

Source

pub fn call_static_object( &self, class: JClass, method: JMethodId, args: &[JValue], ) -> JObject

Source

pub fn call_static_int( &self, class: JClass, method: JMethodId, args: &[JValue], ) -> i32

Source

pub fn call_static_void( &self, class: JClass, method: JMethodId, args: &[JValue], )

Source

pub fn new_object( &self, class: JClass, ctor: JMethodId, args: &[JValue], ) -> JObject

Source

pub fn alloc_object(&self, class: JClass) -> JObject

Allocate without running a constructor.

Source

pub fn new_global_ref(&self, object: JObject) -> JObject

Source

pub fn delete_global_ref(&self, object: JObject)

Source

pub fn delete_local_ref(&self, object: JObject)

Source

pub fn is_same_object(&self, a: JObject, b: JObject) -> bool

Source

pub fn push_local_frame(&self, capacity: i32) -> bool

Push a local frame, so a burst of locals is released together.

The default local-reference table is small — 512 entries on Android — and a scan callback that leaks a few per advertisement exhausts it.

Source

pub fn pop_local_frame(&self)

Source

pub fn new_string(&self, s: &str) -> JString

Source

pub fn get_string(&self, string: JString) -> Option<String>

Source

pub fn array_length(&self, array: JArray) -> i32

Source

pub fn object_array_element(&self, array: JArray, index: i32) -> JObject

Source

pub fn new_object_array( &self, length: i32, class: JClass, initial: JObject, ) -> JArray

Source

pub fn set_object_array_element( &self, array: JArray, index: i32, value: JObject, )

Source

pub fn byte_array(&self, array: JArray) -> Option<Vec<u8>>

Copy a byte[] out of the VM.

Source

pub fn new_byte_array(&self, data: &[u8]) -> JArray

Make a byte[] the VM owns.

Source

pub fn register_natives(&self, class: JClass, methods: &[NativeMethod]) -> bool

Bind Rust functions to a class’s native methods.

Source

pub fn new_direct_byte_buffer(&self, data: *mut u8, len: usize) -> JObject

Wrap memory we own as a java.nio.ByteBuffer the VM can read.

No copy is made, so the memory must outlive every use of the buffer — which for a DEX means the life of the class loader built from it.

Source

pub fn exception_occurred(&self) -> JObject

Source

pub fn exception_clear(&self)

Source

pub fn exception_describe(&self)

Source

pub fn throw_new(&self, class: JClass, message: &str)

Source

pub fn check_exception(&self) -> bool

Clear any pending exception.

A pending exception makes almost every later JNI call undefined, so every wrapper above clears before returning. The alternative — checking at each call site — is the same work done less reliably.

Trait Implementations§

Source§

impl Clone for Env

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Env

Auto Trait Implementations§

§

impl !Send for Env

§

impl !Sync for Env

§

impl Forget for Env

§

impl Freeze for Env

§

impl Move for Env

§

impl RefUnwindSafe for Env

§

impl Unpin for Env

§

impl UnsafeUnpin for Env

§

impl UnwindSafe for Env

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.