use std::fmt;
use std::ptr::null_mut;
pub use ::jni_sys as sys;
use sys::{jobject, jvalue};
mod refs {
mod arg;
mod global;
mod local;
mod ref_;
mod return_;
pub use arg::*;
pub use global::*;
pub use local::*;
pub use ref_::*;
pub use return_::*;
}
mod array;
mod as_jvalue;
mod env;
mod jni_type;
mod string_chars;
mod vm;
pub use array::*;
pub use as_jvalue::*;
pub use env::*;
pub use jni_type::JniType;
pub use refs::*;
pub use string_chars::*;
pub use vm::*;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct CastError;
impl std::error::Error for CastError {}
impl fmt::Display for CastError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Cast failed")
}
}
pub trait ThrowableType: ReferenceType {}
#[doc(hidden)]
pub unsafe trait ReferenceType: JniType + 'static {}
pub unsafe trait AssignableTo<T: ReferenceType>: ReferenceType {}
unsafe impl<T: ReferenceType> AssignableTo<T> for T {}
#[repr(C)] #[doc(hidden)] #[derive(Copy, Clone)]
pub struct ObjectAndEnv {
pub object: jni_sys::jobject,
pub env: *mut jni_sys::JNIEnv,
}
pub unsafe trait AsArg<T>: Sized {
fn as_arg(&self) -> jobject;
fn as_arg_jvalue(&self) -> jvalue {
jvalue { l: self.as_arg() }
}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub struct Null;
unsafe impl<T: ReferenceType, U: AsArg<T>> AsArg<T> for &U {
fn as_arg(&self) -> jobject {
U::as_arg(self)
}
}
unsafe impl<T: ReferenceType, U: AsArg<T>> AsArg<T> for &mut U {
fn as_arg(&self) -> jobject {
U::as_arg(self)
}
}
unsafe impl<T: ReferenceType> AsArg<T> for Null {
fn as_arg(&self) -> jobject {
null_mut()
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Ref<'_, U> {
fn as_arg(&self) -> jobject {
self.as_raw()
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<Ref<'_, U>> {
fn as_arg(&self) -> jobject {
self.map(|r| r.as_raw()).unwrap_or(null_mut())
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<&Ref<'_, U>> {
fn as_arg(&self) -> jobject {
self.map(|r| r.as_raw()).unwrap_or(null_mut())
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Local<'_, U> {
fn as_arg(&self) -> jobject {
self.as_raw()
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<Local<'_, U>> {
fn as_arg(&self) -> jobject {
self.as_ref().map(|r| r.as_raw()).unwrap_or(null_mut())
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<&Local<'_, U>> {
fn as_arg(&self) -> jobject {
self.map(|r| r.as_raw()).unwrap_or(null_mut())
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Global<U> {
fn as_arg(&self) -> jobject {
self.as_raw()
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<Global<U>> {
fn as_arg(&self) -> jobject {
self.as_ref().map(|r| r.as_raw()).unwrap_or(null_mut())
}
}
unsafe impl<T: ReferenceType, U: AssignableTo<T>> AsArg<T> for Option<&Global<U>> {
fn as_arg(&self) -> jobject {
self.map(|r| r.as_raw()).unwrap_or(null_mut())
}
}