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][GlobalRef].
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: *mut _jobject) -> JObject<'local>
pub unsafe fn from_raw(raw: *mut _jobject) -> JObject<'local>
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 JObjectArray<'local>
impl<'local> AsRef<JObject<'local>> for JObjectArray<'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§fn from(other: &'obj_ref JObject<'local>) -> &'obj_ref JObjectArray<'local>
fn from(other: &'obj_ref JObject<'local>) -> &'obj_ref JObjectArray<'local>
Source§impl<'local, 'obj_ref, T> From<&'obj_ref JObject<'local>> for &'obj_ref JPrimitiveArray<'local, T>where
T: TypeArray,
impl<'local, 'obj_ref, T> From<&'obj_ref JObject<'local>> for &'obj_ref JPrimitiveArray<'local, T>where
T: TypeArray,
This conversion assumes that the JObject
is a pointer to a class object.
Source§fn from(
other: &'obj_ref JObject<'local>,
) -> &'obj_ref JPrimitiveArray<'local, T>
fn from( other: &'obj_ref JObject<'local>, ) -> &'obj_ref JPrimitiveArray<'local, T>
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 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§fn from(other: JObject<'_>) -> JObjectArray<'local>
fn from(other: JObject<'_>) -> JObjectArray<'local>
Source§impl<'local, T> From<JObject<'local>> for JPrimitiveArray<'local, T>where
T: TypeArray,
impl<'local, T> From<JObject<'local>> for JPrimitiveArray<'local, T>where
T: TypeArray,
This conversion assumes that the JObject
is a pointer to a class object.