• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::{objects::JObject, sys::jobject};
2 
3 /// Lifetime'd representation of a `jobject` that is an instance of the
4 /// ByteBuffer Java class. Just a `JObject` wrapped in a new class.
5 #[repr(transparent)]
6 #[derive(Clone, Copy, Debug)]
7 pub struct JByteBuffer<'a>(JObject<'a>);
8 
9 impl<'a> ::std::ops::Deref for JByteBuffer<'a> {
10     type Target = JObject<'a>;
11 
deref(&self) -> &Self::Target12     fn deref(&self) -> &Self::Target {
13         &self.0
14     }
15 }
16 
17 impl<'a> From<JByteBuffer<'a>> for JObject<'a> {
from(other: JByteBuffer) -> JObject18     fn from(other: JByteBuffer) -> JObject {
19         other.0
20     }
21 }
22 
23 impl<'a> From<JObject<'a>> for JByteBuffer<'a> {
from(other: JObject) -> Self24     fn from(other: JObject) -> Self {
25         unsafe { Self::from_raw(other.into_raw()) }
26     }
27 }
28 
29 impl<'a> std::default::Default for JByteBuffer<'a> {
default() -> Self30     fn default() -> Self {
31         Self(JObject::null())
32     }
33 }
34 
35 impl<'a> JByteBuffer<'a> {
36     /// Creates a [`JByteBuffer`] that wraps the given `raw` [`jobject`]
37     ///
38     /// # Safety
39     /// No runtime check is made to verify that the given [`jobject`] is an instance of
40     /// a `ByteBuffer`.
from_raw(raw: jobject) -> Self41     pub unsafe fn from_raw(raw: jobject) -> Self {
42         Self(JObject::from_raw(raw as jobject))
43     }
44 
45     /// Unwrap to the raw jni type.
into_raw(self) -> jobject46     pub fn into_raw(self) -> jobject {
47         self.0.into_raw() as jobject
48     }
49 }
50