use crate::{
Env,
errors::*,
objects::{Auto, Global, JObject, Reference},
};
#[cfg(doc)]
use crate::objects::{JClass, JMethodID};
pub unsafe trait Desc<'local, T> {
type Output: AsRef<T>;
fn lookup(self, _: &mut Env<'local>) -> Result<Self::Output>;
}
unsafe impl<'local, T> Desc<'local, T> for T
where
T: AsRef<T>,
{
type Output = Self;
fn lookup(self, _: &mut Env<'local>) -> Result<T> {
Ok(self)
}
}
unsafe impl<'local, T> Desc<'local, T> for &T
where
T: AsRef<T>,
{
type Output = Self;
fn lookup(self, _: &mut Env<'local>) -> Result<Self::Output> {
Ok(self)
}
}
unsafe impl<'local, 'other_local, T> Desc<'local, T> for Auto<'other_local, T>
where
T: AsRef<T> + Into<JObject<'other_local>>,
{
type Output = Self;
fn lookup(self, _: &mut Env<'local>) -> Result<Self::Output> {
Ok(self)
}
}
unsafe impl<'local, 'other_local, T> Desc<'local, T> for &Auto<'other_local, T>
where
T: AsRef<T> + Into<JObject<'other_local>>,
{
type Output = Self;
fn lookup(self, _: &mut Env<'local>) -> Result<Self::Output> {
Ok(self)
}
}
unsafe impl<'local, 'obj_ref, T> Desc<'local, T> for &'obj_ref Global<T>
where
T: Reference
+ AsRef<T>
+ AsRef<JObject<'static>>
+ Into<JObject<'static>>
+ Default
+ Send
+ Sync
+ 'static,
{
type Output = &'obj_ref T;
fn lookup(self, _: &mut Env<'local>) -> Result<Self::Output> {
Ok(self.as_ref())
}
}