Struct jni::objects::AutoLocal

source ·
pub struct AutoLocal<'local, T>where
    T: Into<JObject<'local>>,{ /* private fields */ }
Expand description

Auto-delete wrapper for local refs.

Anything passed to a foreign method and returned from JNI methods is considered a local ref unless it is specified otherwise. These refs are automatically deleted once the foreign method exits, but it’s possible that they may reach the JVM-imposed limit before that happens.

This wrapper provides automatic local ref deletion when it goes out of scope.

See also the JNI specification for details on referencing Java objects and some extra information.

Implementations§

source§

impl<'local, T> AutoLocal<'local, T>where T: Into<JObject<'local>>,

source

pub fn new(obj: T, env: &JNIEnv<'local>) -> Self

Creates a new auto-delete wrapper for a local ref.

Once this wrapper goes out of scope, the delete_local_ref will be called on the object. While wrapped, the object can be accessed via the Deref impl.

source

pub fn forget(self) -> T

Forget the wrapper, returning the original object.

This prevents delete_local_ref from being called when the AutoLocal gets dropped. You must either remember to delete the local ref manually, or be ok with it getting deleted once the foreign method returns.

Trait Implementations§

source§

impl<'local, T, U> AsMut<U> for AutoLocal<'local, T>where T: AsMut<U> + Into<JObject<'local>>,

source§

fn as_mut(&mut self) -> &mut U

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

impl<'local, T, U> AsRef<U> for AutoLocal<'local, T>where T: AsRef<U> + Into<JObject<'local>>,

source§

fn as_ref(&self) -> &U

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

impl<'local, T> Debug for AutoLocal<'local, T>where T: Into<JObject<'local>> + Debug,

source§

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

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

impl<'local, T> Deref for AutoLocal<'local, T>where T: Into<JObject<'local>>,

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'local, T> DerefMut for AutoLocal<'local, T>where T: Into<JObject<'local>>,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'local, 'other_local, 'obj_ref, T> Desc<'local, T> for &'obj_ref AutoLocal<'other_local, T>where T: AsRef<T> + Into<JObject<'other_local>>,

§

type Output = &'obj_ref AutoLocal<'other_local, T>

The type that this Desc returns.
source§

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

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

impl<'local, 'other_local, T> Desc<'local, T> for AutoLocal<'other_local, T>where T: AsRef<T> + Into<JObject<'other_local>>,

§

type Output = AutoLocal<'other_local, T>

The type that this Desc returns.
source§

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

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

impl<'local, T> Drop for AutoLocal<'local, T>where T: Into<JObject<'local>>,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'local, T> RefUnwindSafe for AutoLocal<'local, T>where T: RefUnwindSafe,

§

impl<'local, T> !Send for AutoLocal<'local, T>

§

impl<'local, T> !Sync for AutoLocal<'local, T>

§

impl<'local, T> Unpin for AutoLocal<'local, T>where T: Unpin,

§

impl<'local, T> UnwindSafe for AutoLocal<'local, T>where T: UnwindSafe,

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.