1 use std::marker::PhantomData; 2 3 use crate::sys::jmethodID; 4 5 /// Wrapper around `sys::jmethodid` that adds a lifetime. This prevents it from 6 /// outliving the context in which it was acquired and getting GC'd out from 7 /// under us. It matches C's representation of the raw pointer, so it can be 8 /// used in any of the extern function argument positions that would take a 9 /// `jmethodid`. This represents static methods only since they require a 10 /// different set of JNI signatures. 11 #[repr(transparent)] 12 #[derive(Copy, Clone)] 13 pub struct JStaticMethodID<'a> { 14 internal: jmethodID, 15 lifetime: PhantomData<&'a ()>, 16 } 17 18 impl<'a> From<jmethodID> for JStaticMethodID<'a> { from(other: jmethodID) -> Self19 fn from(other: jmethodID) -> Self { 20 JStaticMethodID { 21 internal: other, 22 lifetime: PhantomData, 23 } 24 } 25 } 26 27 impl<'a> JStaticMethodID<'a> { 28 /// Unwrap to the internal jni type. into_inner(self) -> jmethodID29 pub fn into_inner(self) -> jmethodID { 30 self.internal 31 } 32 } 33