jni_glue/refs/
ref_.rs

1use super::*;
2
3
4
5/// A non-null, [reference](https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jni_refs.html)
6/// to a Java object (+ &[Env]).  This may refer to a [Local], [Global], local [Argument], etc.
7/// 
8/// **Not FFI Safe:**  #\[repr(rust)\], and exact layout is likely to change - depending on exact features used - in the
9/// future.  Specifically, on Android, since we're guaranteed to only have a single ambient VM, we can likely store the
10/// \*const JNIEnv in thread local storage instead of lugging it around in every Local.  Of course, there's no
11/// guarantee that's actually an *optimization*...
12/// 
13/// [Env]:      struct.Env.html
14/// [Local]:    struct.Local.html
15/// [Global]:   struct.Global.html
16/// [Argument]: struct.Argument.html
17pub struct Ref<'env, Class: AsValidJObjectAndEnv> {
18    pub(crate) oae:    ObjectAndEnv,
19    pub(crate) _env:   PhantomData<&'env Env>,
20    pub(crate) _class: PhantomData<&'env Class>,
21}
22
23impl<'env, Class: AsValidJObjectAndEnv> Deref for Ref<'env, Class> {
24    type Target = Class;
25    fn deref(&self) -> &Self::Target {
26        unsafe { &*(&self.oae as *const ObjectAndEnv as *const Self::Target) }
27    }
28}