droid_wrap_utils

Struct JObject

Source
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>

Source

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

pub fn as_raw(&self) -> *mut _jobject

Returns the raw JNI pointer.

Source

pub fn into_raw(self) -> *mut _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 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> AsRef<JObject<'local>> for JPrimitiveArray<'local, T>
where T: TypeArray,

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 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<(), Error>

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

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

Source§

fn default() -> JObject<'local>

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

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

Source§

type Target = *mut _jobject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<JObject<'local> as Deref>::Target

Dereferences the value.
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>) -> &'obj_ref JClass<'local>

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>) -> &'obj_ref JObjectArray<'local>

Converts to this type from the input type.
Source§

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>

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>) -> &'obj_ref JString<'local>

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 JClass<'local>

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

Source§

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

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<'_>) -> JObjectArray<'local>

Converts to this type from the input type.
Source§

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.

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

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> From<JPrimitiveArray<'local, T>> for JObject<'local>
where T: TypeArray,

Source§

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

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<T: FromStr> ParseJObjectType<T> for JObject<'_>

Source§

fn parse(&self, env: &mut JNIEnv<'_>) -> T
where <T as FromStr>::Err: Debug,

Source§

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

Source§

type Error = Error

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

fn try_from(value: JValueGen<JObject<'local>>) -> Result<JObject<'local>, Error>

Performs the conversion.
Source§

impl Send for JObject<'static>

Source§

impl Sync for JObject<'static>

Auto Trait Implementations§

§

impl<'local> Freeze for JObject<'local>

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<'local, T> Desc<'local, T> for T
where T: AsRef<T>,

Source§

type Output = T

The type that this Desc returns.
Source§

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

Look up the concrete type from the JVM. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.