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