droid_wrap_utils

Struct GlobalRef

Source
pub struct GlobalRef { /* private fields */ }
Expand description

A global JVM reference. These are “pinned” by the garbage collector and are guaranteed to not get collected until released. Thus, this is allowed to outlive the JNIEnv that it came from and can be used in other threads.

GlobalRef can be cloned to use the same global reference in different contexts. If you want to create yet another global ref to the same java object you may call JNIEnv#new_global_ref just like you do when create GlobalRef from a local reference.

Underlying global reference will be dropped, when the last instance of GlobalRef leaves its scope.

It is recommended that a native thread that drops the global reference is attached to the Java thread (i.e., has an instance of JNIEnv). If the native thread is not attached, the GlobalRef#drop will print a warning and implicitly attach and detach it, which significantly affects performance.

Implementations§

Source§

impl GlobalRef

Source

pub fn as_obj(&self) -> &JObject<'static>

Get the object from the global ref

This borrows the ref and prevents it from being dropped as long as the JObject sticks around.

Methods from Deref<Target = JObject<'static>>§

Source

pub fn as_raw(&self) -> *mut _jobject

Returns the raw JNI pointer.

Trait Implementations§

Source§

impl AsRef<GlobalRef> for GlobalRef

Source§

fn as_ref(&self) -> &GlobalRef

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<JObject<'static>> for GlobalRef

Source§

fn as_ref(&self) -> &JObject<'static>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for GlobalRef

Source§

fn clone(&self) -> GlobalRef

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for GlobalRef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for GlobalRef

Source§

type Target = JObject<'static>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<GlobalRef as Deref>::Target

Dereferences the value.
Source§

impl<'local, 'obj_ref> Desc<'local, JClass<'static>> for &'obj_ref GlobalRef

This conversion assumes that the GlobalRef is a pointer to a class object.

Source§

type Output = &'obj_ref JClass<'static>

The type that this Desc returns.
Source§

fn lookup( self, _: &mut JNIEnv<'local>, ) -> Result<<&'obj_ref GlobalRef as Desc<'local, JClass<'static>>>::Output, Error>

Look up the concrete type from the JVM. Read more

Auto Trait Implementations§

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, dst: *mut u8)

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

impl<'local, T> Desc<'local, T> for T
where T: AsRef<T>,

Source§

type Output = T

The type that this Desc returns.
Source§

fn lookup(self, _: &mut JNIEnv<'local>) -> Result<T, Error>

Look up the concrete type from the JVM. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.