diff options
Diffstat (limited to 'src/wrapper/objects/jthrowable.rs')
-rw-r--r-- | src/wrapper/objects/jthrowable.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/wrapper/objects/jthrowable.rs b/src/wrapper/objects/jthrowable.rs index 03edc46..f77f6e3 100644 --- a/src/wrapper/objects/jthrowable.rs +++ b/src/wrapper/objects/jthrowable.rs @@ -9,12 +9,6 @@ use crate::{ #[derive(Clone, Copy)] pub struct JThrowable<'a>(JObject<'a>); -impl<'a> From<jthrowable> for JThrowable<'a> { - fn from(other: jthrowable) -> Self { - JThrowable(From::from(other as jobject)) - } -} - impl<'a> ::std::ops::Deref for JThrowable<'a> { type Target = JObject<'a>; @@ -30,7 +24,29 @@ impl<'a> From<JThrowable<'a>> for JObject<'a> { } impl<'a> From<JObject<'a>> for JThrowable<'a> { - fn from(other: JObject) -> JThrowable { - (other.into_inner() as jthrowable).into() + fn from(other: JObject) -> Self { + unsafe { Self::from_raw(other.into_raw()) } + } +} + +impl<'a> std::default::Default for JThrowable<'a> { + fn default() -> Self { + Self(JObject::null()) + } +} + +impl<'a> JThrowable<'a> { + /// Creates a [`JThrowable`] that wraps the given `raw` [`jthrowable`] + /// + /// # Safety + /// + /// Expects a valid pointer or `null` + pub unsafe fn from_raw(raw: jthrowable) -> Self { + Self(JObject::from_raw(raw as jobject)) + } + + /// Unwrap to the raw jni type. + pub fn into_raw(self) -> jthrowable { + self.0.into_raw() as jthrowable } } |