pub trait TryFromJavaValue<'env: 'borrow, 'borrow>where
    Self: Sized + Signature,{
    type Source: JavaValue<'env>;

    const SIG_TYPE: &'static str = <Self as Signature>::SIG_TYPE;

    // Required method
    fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>;
}
Expand description

Conversion trait from Java values to Rust values, analogous to TryFrom. Used when converting types that are input to JNI-available functions.

This is the default trait used when converting values from Java to Rust.

Notes on the derive macro

When using the derive macro, the deriving struct must have a AutoLocal field annotated with both 'env and 'borrow lifetimes and a #[instance] attribute. This fields keeps a local reference to the underlying Java object. All other fields are automatically initialized from fields on the Java instance with the same name.

Example:

use robusta_jni::convert::{Signature, TryFromJavaValue};
use robusta_jni::jni::objects::AutoLocal;

#[derive(Signature, TryFromJavaValue)]
#[package()]
struct A<'env: 'borrow, 'borrow> {
    #[instance]
    raw: AutoLocal<'env, 'borrow>,
    foo: i32
}

Required Associated Types§

source

type Source: JavaValue<'env>

Conversion source type.

Provided Associated Constants§

source

const SIG_TYPE: &'static str = <Self as Signature>::SIG_TYPE

Signature of the target type. By default, use the one defined on the Signature trait for the implementing type.

Required Methods§

source

fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>

Perform the conversion.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for bool

§

type Source = u8

source§

fn try_from(s: Self::Source, _env: &JNIEnv<'env>) -> Result<Self>

source§

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for char

§

type Source = u16

source§

fn try_from(s: Self::Source, _env: &JNIEnv<'env>) -> Result<Self>

source§

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for Box<[bool]>

§

type Source = *mut _jobject

source§

fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>

source§

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for Box<[u8]>

§

type Source = *mut _jobject

source§

fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Box<[u8]>>

source§

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for String

§

type Source = JString<'env>

source§

fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>

source§

impl<'env: 'borrow, 'borrow, T, U> TryFromJavaValue<'env, 'borrow> for Vec<T>where T: TryFromJavaValue<'env, 'borrow, Source = U>, U: JavaValue<'env>,

§

type Source = JObject<'env>

source§

fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>

Implementors§

source§

impl<'env: 'borrow, 'borrow, T> TryFromJavaValue<'env, 'borrow> for Twhere T: JavaValue<'env> + Signature,

§

type Source = T