pub struct JVm { /* private fields */ }
Implementations§
Source§impl JVm
impl JVm
pub const DEFAULT_VERSION: JInt = 65_542i32
pub fn as_sys(&self) -> *mut JavaVM
pub fn from_sys(vm: *mut JavaVM) -> Option<Self>
pub fn from_void(vm: *mut c_void) -> Option<Self>
Sourcepub fn singleton(v: Option<JVm>) -> Option<JVm>
pub fn singleton(v: Option<JVm>) -> Option<JVm>
Examples found in repository?
examples/nama.rs (line 53)
50 fn MyInterface_class(env: Option<&JEnv>) -> Option<JClassID> {
51 const MY_INTERFACE_NAME: &'static [u8] = b"MyInterface\0";
52 static CACHE: CachedID = CachedID::new();
53 CACHE.get(|| env.unwrap_or(JVm::singleton(None)?.env()?).find_class(MY_INTERFACE_NAME))
54 }
55 fn bar(&self, env: &JEnv) -> Option<()> {
56 static CACHE: CachedID = CachedID::new();
57 CACHE
58 .get(|| Self::MyInterface_class(Some(env))?.method(env, b"bar\0", b"()V\0"))?
59 .call(env, self.as_ref(), ())
60 }
61 }
62 pub struct MyInterfaceObject {
63 inner: JObject,
64 }
65 impl MyInterface for MyInterfaceObject {}
66 impl AsRef<JObject> for MyInterfaceObject {
67 fn as_ref(&self) -> &JObject {
68 &self.inner
69 }
70 }
71
72 #[no_mangle]
73 #[allow(non_snake_case)]
74 extern "system" fn Java_Hello_print(env: &JEnv, hello: &Hello, i: JInt) {
75 println!("[Rust] Hello print called {i}");
76 hello.play(env);
77 }
78 #[no_mangle]
79 #[allow(non_snake_case)]
80 extern "system" fn Java_HelloOne_printone(env: &JEnv, hello: &Hello) {
81 println!("[Rust] Hello printone called");
82 hello.play(env);
83 hello.bar(env);
84 }
85 #[no_mangle]
86 #[allow(non_snake_case)]
87 extern "system" fn Java_HelloTwo_printtwo(env: &JEnv, hello: &Hello) {
88 println!("[Rust] Hello printtwo called");
89 hello.play(env);
90 hello.bar(env);
91 }
92}
93mod world {
94 use jnim::{CachedID, JClassID, JEnv, JInt, JNameMaker, JObject, JPlainMarker};
95
96 #[no_mangle]
97 #[allow(non_snake_case)]
98 extern "system" fn Java_World_print(env: &JEnv, world: &World, i: JInt) {
99 println!("[Rust] World print called {i}");
100 world.play(env);
101 world.get_state(env).map(|value| world.set_state(env, value + 100));
102 }
103
104 struct World {
105 __supper: JObject,
106 }
107 impl AsRef<JObject> for World {
108 fn as_ref(&self) -> &JObject {
109 &self.__supper
110 }
111 }
112 impl JNameMaker for World {
113 const JAVA_PATH: &'static [u8] = b"World\0";
114 }
115 impl JPlainMarker for World {
116 fn class(env: Option<&JEnv>) -> Option<JClassID> {
117 static CACHE: CachedID = CachedID::new();
118 CACHE.get(|| JEnv::env(env)?.find_class(Self::JAVA_PATH))
119 }
120 }
121 impl World {
122 fn get_state(&self, env: &JEnv) -> Option<JInt> {
123 static CACHE: CachedID = CachedID::new();
124 CACHE
125 .get(|| Self::class(Some(env))?.field(env, b"state\0", b"I\0"))?
126 .get(env, self.as_ref())
127 }
128 fn set_state(&self, env: &JEnv, value: JInt) -> Option<()> {
129 static CACHE: CachedID = CachedID::new();
130 CACHE
131 .get(|| Self::class(Some(env))?.field(env, b"state\0", b"I\0"))?
132 .set(env, self.as_ref(), value)
133 }
134 fn play(&self, env: &JEnv) -> Option<()> {
135 static CACHE: CachedID = CachedID::new();
136 CACHE
137 .get(|| Self::class(Some(env))?.method(env, b"play\0", b"()V\0"))?
138 .call(env, self.as_ref(), ())
139 }
140 }
141}
142
143#[no_mangle]
144#[allow(non_snake_case)]
145extern "system" fn JNI_OnLoad(vm: JVm, _: &JVoid) -> JInt {
146 JVm::singleton(Some(vm));
147 JVm::DEFAULT_VERSION
148}
pub fn attach(&self) -> Option<&'static JEnv>
pub fn attach_as_daemon(&self) -> Option<&'static JEnv>
pub fn detach(&self)
pub fn env_with_version(&self, version: jint) -> Option<&'static JEnv>
pub fn env_1_6(&self) -> Option<&'static JEnv>
pub fn env_1_4(&self) -> Option<&'static JEnv>
pub fn env_1_2(&self) -> Option<&'static JEnv>
pub fn env_1_1(&self) -> Option<&'static JEnv>
Trait Implementations§
impl Copy for JVm
impl Send for JVm
impl Sync for JVm
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more