1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
use std::marker::PhantomData;
use crate::{
objects::JObject,
sys::{jarray, jobject},
};
use super::TypeArray;
#[cfg(doc)]
use crate::JNIEnv;
#[repr(transparent)]
#[derive(Debug)]
pub struct JPrimitiveArray<'local, T: TypeArray> {
obj: JObject<'local>,
lifetime: PhantomData<&'local T>,
}
impl<'local, T: TypeArray> AsRef<JPrimitiveArray<'local, T>> for JPrimitiveArray<'local, T> {
fn as_ref(&self) -> &JPrimitiveArray<'local, T> {
self
}
}
impl<'local, T: TypeArray> AsMut<JPrimitiveArray<'local, T>> for JPrimitiveArray<'local, T> {
fn as_mut(&mut self) -> &mut JPrimitiveArray<'local, T> {
self
}
}
impl<'local, T: TypeArray> AsRef<JObject<'local>> for JPrimitiveArray<'local, T> {
fn as_ref(&self) -> &JObject<'local> {
&self.obj
}
}
impl<'local, T: TypeArray> ::std::ops::Deref for JPrimitiveArray<'local, T> {
type Target = JObject<'local>;
fn deref(&self) -> &Self::Target {
&self.obj
}
}
impl<'local, T: TypeArray> From<JPrimitiveArray<'local, T>> for JObject<'local> {
fn from(other: JPrimitiveArray<'local, T>) -> JObject {
other.obj
}
}
impl<'local, T: TypeArray> From<JObject<'local>> for JPrimitiveArray<'local, T> {
fn from(other: JObject) -> Self {
unsafe { Self::from_raw(other.into_raw()) }
}
}
impl<'local, 'obj_ref, T: TypeArray> From<&'obj_ref JObject<'local>>
for &'obj_ref JPrimitiveArray<'local, T>
{
fn from(other: &'obj_ref JObject<'local>) -> Self {
unsafe { &*(other as *const JObject<'local> as *const JPrimitiveArray<'local, T>) }
}
}
impl<'local, T: TypeArray> std::default::Default for JPrimitiveArray<'local, T> {
fn default() -> Self {
Self {
obj: JObject::null(),
lifetime: PhantomData,
}
}
}
impl<'local, T: TypeArray> JPrimitiveArray<'local, T> {
pub unsafe fn from_raw(raw: jarray) -> Self {
Self {
obj: JObject::from_raw(raw as jobject),
lifetime: PhantomData,
}
}
pub fn into_raw(self) -> jarray {
self.obj.into_raw() as jarray
}
}
pub type JBooleanArray<'local> = JPrimitiveArray<'local, crate::sys::jboolean>;
pub type JByteArray<'local> = JPrimitiveArray<'local, crate::sys::jbyte>;
pub type JCharArray<'local> = JPrimitiveArray<'local, crate::sys::jchar>;
pub type JShortArray<'local> = JPrimitiveArray<'local, crate::sys::jshort>;
pub type JIntArray<'local> = JPrimitiveArray<'local, crate::sys::jint>;
pub type JLongArray<'local> = JPrimitiveArray<'local, crate::sys::jlong>;
pub type JFloatArray<'local> = JPrimitiveArray<'local, crate::sys::jfloat>;
pub type JDoubleArray<'local> = JPrimitiveArray<'local, crate::sys::jdouble>;
pub unsafe trait AsJArrayRaw<'local>: AsRef<JObject<'local>> {
fn as_jarray_raw(&self) -> jarray {
self.as_ref().as_raw() as jarray
}
}
unsafe impl<'local, T: TypeArray> AsJArrayRaw<'local> for JPrimitiveArray<'local, T> {}