uni_tmp_jni/wrapper/objects/
jclass.rs

1use crate::{
2    objects::JObject,
3    sys::{jclass, jobject},
4};
5
6/// Lifetime'd representation of a `jclass`. Just a `JObject` wrapped in a new
7/// class.
8#[repr(transparent)]
9#[derive(Clone, Copy, Debug)]
10pub struct JClass<'a>(JObject<'a>);
11
12impl<'a> From<jclass> for JClass<'a> {
13    fn from(other: jclass) -> Self {
14        JClass(From::from(other as jobject))
15    }
16}
17
18impl<'a> ::std::ops::Deref for JClass<'a> {
19    type Target = JObject<'a>;
20
21    fn deref(&self) -> &Self::Target {
22        &self.0
23    }
24}
25
26impl<'a> From<JClass<'a>> for JObject<'a> {
27    fn from(other: JClass) -> JObject {
28        other.0
29    }
30}
31
32/// This conversion assumes that the `JObject` is a pointer to a class object.
33impl<'a> From<JObject<'a>> for JClass<'a> {
34    fn from(other: JObject) -> JClass {
35        (other.into_inner() as jclass).into()
36    }
37}