java_spaghetti/refs/
return_.rs

1use std::marker::PhantomData;
2use std::ptr::null_mut;
3
4use jni_sys::jobject;
5
6use crate::ReferenceType;
7
8/// FFI: Use **Return\<java::lang::Object\>** instead of jobject.  This represents a (null?) JNI function call return value.
9///
10/// Unlike most Java reference types from this library, this *can* be null.
11///
12/// FFI safe where a jobject is safe, assuming you match your types correctly.
13#[repr(transparent)]
14pub struct Return<'env, T: ReferenceType> {
15    object: jobject,
16    _class: PhantomData<&'env T>,
17}
18
19impl<'env, T: ReferenceType> Return<'env, T> {
20    pub unsafe fn from_raw(object: jobject) -> Self {
21        Self {
22            object,
23            _class: PhantomData,
24        }
25    }
26
27    pub fn null() -> Self {
28        Self {
29            object: null_mut(),
30            _class: PhantomData,
31        }
32    }
33
34    pub fn as_raw(&self) -> jobject {
35        self.object
36    }
37}