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`. 10 #[repr(transparent)] 11 #[derive(Copy, Clone, Debug)] 12 pub struct JMethodID<'a> { 13 internal: jmethodID, 14 lifetime: PhantomData<&'a ()>, 15 } 16 17 impl<'a> From<jmethodID> for JMethodID<'a> { from(other: jmethodID) -> Self18 fn from(other: jmethodID) -> Self { 19 JMethodID { 20 internal: other, 21 lifetime: PhantomData, 22 } 23 } 24 } 25 26 impl<'a> JMethodID<'a> { 27 /// Unwrap to the internal jni type. into_inner(self) -> jmethodID28 pub fn into_inner(self) -> jmethodID { 29 self.internal 30 } 31 } 32