Struct jni::objects::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) -> 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

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

impl Deref for GlobalRef

§

type Target = JObject<'static>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::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.

§

type Output = &'obj_ref JClass<'static>

The type that this Desc returns.
source§

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

Look up the concrete type from the JVM. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.