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
use crate::sys::{
    JNI_VERSION_1_1, JNI_VERSION_1_2, JNI_VERSION_1_4, JNI_VERSION_1_6, JNI_VERSION_1_8,
};

/// JNI Version
///
/// This maps to the `jni_sys::JNI_VERSION_1_*` constants.
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
pub enum JNIVersion {
    V1,
    V2,
    V4,
    V6,
    V8,
    Invalid(i32),
}

impl From<i32> for JNIVersion {
    fn from(other: i32) -> Self {
        match other {
            JNI_VERSION_1_1 => JNIVersion::V1,
            JNI_VERSION_1_2 => JNIVersion::V2,
            JNI_VERSION_1_4 => JNIVersion::V4,
            JNI_VERSION_1_6 => JNIVersion::V6,
            JNI_VERSION_1_8 => JNIVersion::V8,
            v => JNIVersion::Invalid(v),
        }
    }
}

impl From<JNIVersion> for i32 {
    fn from(other: JNIVersion) -> Self {
        match other {
            JNIVersion::V1 => JNI_VERSION_1_1,
            JNIVersion::V2 => JNI_VERSION_1_2,
            JNIVersion::V4 => JNI_VERSION_1_4,
            JNIVersion::V6 => JNI_VERSION_1_6,
            JNIVersion::V8 => JNI_VERSION_1_8,
            JNIVersion::Invalid(v) => v,
        }
    }
}