Struct jni::objects::JObject

source ·
#[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>

source

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.
source

pub fn as_raw(&self) -> jobject

Returns the raw JNI pointer.

source

pub fn into_raw(self) -> jobject

Unwrap to the internal jni type.

source

pub fn null() -> JObject<'static>

Creates a new null reference.

Null references are always valid and do not belong to a local reference frame. Therefore, the returned JObject always has the 'static lifetime.

Trait Implementations§

source§

impl<'local> AsMut<JObject<'local>> for JObject<'local>

source§

fn as_mut(&mut self) -> &mut JObject<'local>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<'local> AsRef<JObject<'local>> for JByteBuffer<'local>

source§

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

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

impl<'local> AsRef<JObject<'local>> for JClass<'local>

source§

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

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

impl<'local> AsRef<JObject<'local>> for JObject<'local>

source§

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

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

impl<'local> AsRef<JObject<'local>> for JObjectArray<'local>

source§

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

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

impl<'local, T: TypeArray> AsRef<JObject<'local>> for JPrimitiveArray<'local, T>

source§

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

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

impl<'local> AsRef<JObject<'local>> for JString<'local>

source§

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

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

impl<'local> AsRef<JObject<'local>> for JThrowable<'local>

source§

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

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

impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JList<'local, 'other_local_1, 'obj_ref>

source§

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

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

impl<'local, 'other_local_1: 'obj_ref, 'obj_ref> AsRef<JObject<'other_local_1>> for JMap<'local, 'other_local_1, 'obj_ref>

source§

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

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<'local> Debug for JObject<'local>

source§

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

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

impl<'local> Default for JObject<'local>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'local> Deref for JObject<'local>

§

type Target = *mut _jobject

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JByteBuffer<'local>

source§

fn from(other: &'obj_ref JObject<'local>) -> Self

Converts to this type from the input type.
source§

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§

fn from(other: &'obj_ref JObject<'local>) -> Self

Converts to this type from the input type.
source§

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>) -> Self

Converts to this type from the input type.
source§

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§

fn from(other: &'obj_ref JObject<'local>) -> Self

Converts to this type from the input type.
source§

impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JString<'local>

source§

fn from(other: &'obj_ref JObject<'local>) -> Self

Converts to this type from the input type.
source§

impl<'local, 'obj_ref> From<&'obj_ref JObject<'local>> for &'obj_ref JThrowable<'local>

source§

fn from(other: &'obj_ref JObject<'local>) -> Self

Converts to this type from the input type.
source§

impl<'local> From<JByteBuffer<'local>> for JObject<'local>

source§

fn from(other: JByteBuffer<'_>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local> From<JClass<'local>> for JObject<'local>

source§

fn from(other: JClass<'_>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local> From<JObject<'local>> for JByteBuffer<'local>

source§

fn from(other: JObject<'_>) -> Self

Converts to this type from the input type.
source§

impl<'local> From<JObject<'local>> for JClass<'local>

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

source§

fn from(other: JObject<'_>) -> Self

Converts to this type from the input type.
source§

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<'_>) -> Self

Converts to this type from the input type.
source§

impl<'local, T: TypeArray> From<JObject<'local>> for JPrimitiveArray<'local, T>

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

source§

fn from(other: JObject<'_>) -> Self

Converts to this type from the input type.
source§

impl<'local> From<JObject<'local>> for JString<'local>

source§

fn from(other: JObject<'_>) -> Self

Converts to this type from the input type.
source§

impl<'local> From<JObject<'local>> for JThrowable<'local>

source§

fn from(other: JObject<'_>) -> Self

Converts to this type from the input type.
source§

impl<'local> From<JObjectArray<'local>> for JObject<'local>

source§

fn from(other: JObjectArray<'_>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local, T: TypeArray> From<JPrimitiveArray<'local, T>> for JObject<'local>

source§

fn from(other: JPrimitiveArray<'local, T>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local> From<JString<'local>> for JObject<'local>

source§

fn from(other: JString<'_>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local> From<JThrowable<'local>> for JObject<'local>

source§

fn from(other: JThrowable<'_>) -> JObject<'_>

Converts to this type from the input type.
source§

impl<'local> TryFrom<JValueGen<JObject<'local>>> for JObject<'local>

§

type Error = Error

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

fn try_from(value: JValueOwned<'local>) -> Result<Self>

Performs the conversion.
source§

impl Send for JObject<'static>

source§

impl Sync for JObject<'static>

Auto Trait Implementations§

§

impl<'local> RefUnwindSafe for JObject<'local>

§

impl<'local> Unpin for JObject<'local>

§

impl<'local> UnwindSafe for JObject<'local>

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, 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.