#[repr(transparent)]pub struct JObject<'local> { /* private fields */ }
Expand description
Wrapper around [sys::jobject
] that adds a lifetime to ensure that
the underlying JNI pointer won’t be accessible to safe Rust code if the
object reference is released.
It matches C’s representation of the raw pointer, so it can be used in any
of the extern function argument positions that would take a jobject
.
Most other types in the objects
module deref to this, as they do in the C
representation.
The lifetime 'local
represents the local reference frame that this
reference belongs to. See the JNIEnv
documentation for more information
about local reference frames. If 'local
is 'static
, then this reference
does not belong to a local reference frame, that is, it is either null or a
global reference.
Note that an owned JObject
is always a local reference and will never
have the 'static
lifetime. GlobalRef
does implement
AsRef<JObject<’static>>
, but this only yields a
borrowed &JObject<'static>
, never an owned JObject<'static>
.
Local references belong to a single thread and are not safe to share across
threads. This type implements Send
and Sync
if and only if the
lifetime 'local
is 'static
.
Implementations§
source§impl<'local> JObject<'local>
impl<'local> JObject<'local>
sourcepub unsafe fn from_raw(raw: jobject) -> Self
pub unsafe fn from_raw(raw: jobject) -> Self
Creates a JObject
that wraps the given raw
jobject
Safety
raw
may be a null pointer. If raw
is not a null pointer, then:
raw
must be a valid raw JNI local reference.- There must not be any other
JObject
representing the same local reference. - The lifetime
'local
must not outlive the local reference frame that the local reference was created in.
Trait Implementations§
source§impl<'local> AsRef<JObject<'local>> for JByteBuffer<'local>
impl<'local> AsRef<JObject<'local>> for JByteBuffer<'local>
source§impl<'local> AsRef<JObject<'local>> for JObjectArray<'local>
impl<'local> AsRef<JObject<'local>> for JObjectArray<'local>
source§impl<'local> AsRef<JObject<'local>> for JThrowable<'local>
impl<'local> AsRef<JObject<'local>> for JThrowable<'local>
source§impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JList<'local, 'other_local_1, 'obj_ref>
impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JList<'local, 'other_local_1, 'obj_ref>
source§impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JMap<'local, 'other_local_1, 'obj_ref>
impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JMap<'local, 'other_local_1, 'obj_ref>
source§impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JByteBuffer<'local>
impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JByteBuffer<'local>
source§impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JClass<'local>
impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JClass<'local>
This conversion assumes that the JObject
is a pointer to a class object.
source§impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JObjectArray<'local>
impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JObjectArray<'local>
This conversion assumes that the JObject
is a pointer to a class object.
source§impl<'local, 'obj_ref, T: TypeArray> From<&'obj_ref JObject<'local>> for &'obj_ref JPrimitiveArray<'local, T>
impl<'local, 'obj_ref, T: TypeArray> From<&'obj_ref JObject<'local>> for &'obj_ref JPrimitiveArray<'local, T>
This conversion assumes that the JObject
is a pointer to a class object.
source§impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JThrowable<'local>
impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JThrowable<'local>
source§impl<'local> From<JByteBuffer<'local>> for JObject<'local>
impl<'local> From<JByteBuffer<'local>> for JObject<'local>
source§fn from(other: JByteBuffer<'_>) -> JObject<'_>
fn from(other: JByteBuffer<'_>) -> JObject<'_>
source§impl<'local> From<JObject<'local>> for JByteBuffer<'local>
impl<'local> From<JObject<'local>> for JByteBuffer<'local>
source§impl<'local> From<JObject<'local>> for JClass<'local>
impl<'local> From<JObject<'local>> for JClass<'local>
This conversion assumes that the JObject
is a pointer to a class object.
source§impl<'local> From<JObject<'local>> for JObjectArray<'local>
impl<'local> From<JObject<'local>> for JObjectArray<'local>
This conversion assumes that the JObject
is a pointer to a class object.
source§impl<'local, T: TypeArray> From<JObject<'local>> for JPrimitiveArray<'local, T>
impl<'local, T: TypeArray> From<JObject<'local>> for JPrimitiveArray<'local, T>
This conversion assumes that the JObject
is a pointer to a class object.