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>; }
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
}

Associated Types

Conversion source type.

Associated Constants

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

Required methods

Perform the conversion.

Implementations on Foreign Types

Implementors