Trait robusta_jni::convert::safe::TryFromJavaValue[][src]

pub trait TryFromJavaValue<'env: 'borrow, 'borrow> where
    Self: Sized + Signature
{ type Source: JavaValue<'env>; const SIG_TYPE: &'static str; fn try_from(s: Self::Source, env: &'borrow JNIEnv<'env>) -> Result<Self>; }

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
}

Associated Types

type Source: JavaValue<'env>[src]

Conversion source type.

Loading content...

Associated Constants

const SIG_TYPE: &'static str[src]

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

Loading content...

Required methods

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

Perform the conversion.

Loading content...

Implementations on Foreign Types

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for String[src]

type Source = JString<'env>

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

type Source = jboolean

impl<'env: 'borrow, 'borrow> TryFromJavaValue<'env, 'borrow> for char[src]

type Source = jchar

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

type Source = jbooleanArray

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

type Source = JObject<'env>

Loading content...

Implementors

impl<'env: 'borrow, 'borrow, T> TryFromJavaValue<'env, 'borrow> for T where
    T: JavaValue<'env> + Signature
[src]

type Source = T

Loading content...