Struct java_spaghetti::Local

source ·
pub struct Local<'env, T: ReferenceType> { /* private fields */ }
Expand description

A Local, non-null, reference to a Java object (+ Env) limited to the current thread/stack.

Including the env allows for the convenient execution of methods without having to individually pass the env as an argument to each and every one. Since this is limited to the current thread/stack, these cannot be sanely stored in any kind of static storage, nor shared between threads - instead use a Global if you need to do either.

Will DeleteLocalRef when dropped, invalidating the jobject but ensuring threads that rarely or never return to Java may run without being guaranteed to eventually exhaust their local reference limit. If this is not desired, convert to a plain Ref with:

let local = Local::leak(local);

Not FFI Safe: #[repr(rust)], and exact layout is likely to change - depending on exact features used - in the future. Specifically, on Android, since we’re guaranteed to only have a single ambient VM, we can likely store the *const JNIEnv in thread local storage instead of lugging it around in every Local. Of course, there’s no guarantee that’s actually an optimization

Implementations§

source§

impl<'env, T: ReferenceType> Local<'env, T>

source

pub unsafe fn from_raw(env: Env<'env>, object: jobject) -> Self

source

pub fn env(&self) -> Env<'env>

source

pub fn as_raw(&self) -> jobject

source

pub fn into_raw(self) -> jobject

source

pub fn leak(self) -> Ref<'env, T>

source

pub fn as_global(&self) -> Global<T>

source

pub fn as_ref(&self) -> Ref<'_, T>

source

pub fn as_return(&self) -> Return<'env, T>

source

pub fn into_return(self) -> Return<'env, T>

source

pub fn cast<U: ReferenceType>(&self) -> Result<Local<'env, U>, CastError>

source

pub fn upcast<U: ReferenceType>(&self) -> Local<'env, U>
where Self: AssignableTo<U>,

Trait Implementations§

source§

impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Local<'_, U>

source§

impl<'env, T: ReferenceType> Clone for Local<'env, T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'env, T: ReferenceType + Debug> Debug for Local<'env, T>

source§

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

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

impl<'env, T: ReferenceType> Deref for Local<'env, T>

§

type Target = T

The resulting type after dereferencing.
source§

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

Dereferences the value.
source§

impl<'env, T: ReferenceType + Display> Display for Local<'env, T>

source§

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

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

impl<'env, T: ReferenceType> Drop for Local<'env, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'env, T: ReferenceType> From<&Local<'env, T>> for Global<T>

source§

fn from(x: &Local<'env, T>) -> Self

Converts to this type from the input type.
source§

impl<'env, T: ReferenceType> From<&Local<'env, T>> for Local<'env, T>

source§

fn from(x: &Local<'env, T>) -> Self

Converts to this type from the input type.
source§

impl<'env, T: ReferenceType> From<&Ref<'env, T>> for Local<'env, T>

source§

fn from(x: &Ref<'env, T>) -> Self

Converts to this type from the input type.
source§

impl<'env, T: ReferenceType> From<Local<'env, T>> for Global<T>

source§

fn from(x: Local<'env, T>) -> Self

Converts to this type from the input type.
source§

impl<'env, T: ReferenceType> From<Ref<'env, T>> for Local<'env, T>

source§

fn from(x: Ref<'env, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'env, T> Freeze for Local<'env, T>
where T: JniType + 'static,

§

impl<'env, T> RefUnwindSafe for Local<'env, T>
where T: JniType + 'static + RefUnwindSafe,

§

impl<'env, T> !Send for Local<'env, T>

§

impl<'env, T> !Sync for Local<'env, T>

§

impl<'env, T> Unpin for Local<'env, T>
where T: JniType + 'static,

§

impl<'env, T> !UnwindSafe for Local<'env, T>

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<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<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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

§

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.