pub struct Ref<'env, T: ReferenceType> { /* private fields */ }Expand description
A non-null, reference to a Java object (+ Env). This may refer to a Local, Global, local Arg, etc.
Ref guarantees not to have a Drop implementation. It does not own the JNI reference.
Not FFI Safe: #[repr(rust)], and exact layout is likely to change - depending on exact features used - in the
future. Specifically, on Android, since we’re guaranteed to only have a single ambient VM, we can likely store the
*const JNIEnv in thread local storage instead of lugging it around in every Ref. Of course, there’s no
guarantee that’s actually an optimization…
Implementations§
Source§impl<'env, T: ReferenceType> Ref<'env, T>
impl<'env, T: ReferenceType> Ref<'env, T>
Sourcepub fn as_global(&self) -> Global<T>
pub fn as_global(&self) -> Global<T>
Returns a new JNI global reference of the same Java object.
Sourcepub fn as_local(&self) -> Local<'env, T>
pub fn as_local(&self) -> Local<'env, T>
Returns a new JNI local reference of the same Java object.
Sourcepub fn as_monitor(&'env self) -> Monitor<'env, T>
pub fn as_monitor(&'env self) -> Monitor<'env, T>
Enters monitored mode or increments the JNI monitor counter in this thread for the referenced Java object. See Monitor for the limited locking functionality.
Sourcepub fn is_same_object<O: ReferenceType>(&self, other: &Ref<'_, O>) -> bool
pub fn is_same_object<O: ReferenceType>(&self, other: &Ref<'_, O>) -> bool
Tests whether two JNI references refer to the same Java object.
Sourcepub unsafe fn cast_unchecked<U: ReferenceType>(self) -> Ref<'env, U>
pub unsafe fn cast_unchecked<U: ReferenceType>(self) -> Ref<'env, U>
Casts itself to a JNI reference of type U forcefully, without the cost of runtime checking.
§Safety
selfreferences an instance of typeU.
Sourcepub fn cast<U: ReferenceType>(self) -> Result<Ref<'env, U>, CastError>
pub fn cast<U: ReferenceType>(self) -> Result<Ref<'env, U>, CastError>
Tries to cast itself to a JNI reference of type U.
Sourcepub fn upcast<U: ReferenceType>(self) -> Ref<'env, U>where
T: AssignableTo<U>,
pub fn upcast<U: ReferenceType>(self) -> Ref<'env, U>where
T: AssignableTo<U>,
Casts itself towards a super class type, without the cost of runtime checking.
Sourcepub unsafe fn cast_ref_unchecked<U: ReferenceType>(&self) -> &Ref<'env, U>
pub unsafe fn cast_ref_unchecked<U: ReferenceType>(&self) -> &Ref<'env, U>
Casts the borrowed Ref to a JNI reference of type U forcefully, without the cost of runtime checking.
§Safety
selfreferences an instance of typeU.
Sourcepub fn cast_ref<U: ReferenceType>(&self) -> Result<&Ref<'env, U>, CastError>
pub fn cast_ref<U: ReferenceType>(&self) -> Result<&Ref<'env, U>, CastError>
Tries to cast the borrowed Ref to a JNI reference of type U.
Sourcepub fn upcast_ref<U: ReferenceType>(&self) -> &Ref<'env, U>where
T: AssignableTo<U>,
pub fn upcast_ref<U: ReferenceType>(&self) -> &Ref<'env, U>where
T: AssignableTo<U>,
Casts the borrowed Ref towards a super class type, without the cost of runtime checking.