Struct JVm

Source
pub struct JVm { /* private fields */ }

Implementations§

Source§

impl JVm

Source

pub const DEFAULT_VERSION: JInt = 65_542i32

Source

pub fn as_sys(&self) -> *mut JavaVM

Source

pub fn from_sys(vm: *mut JavaVM) -> Option<Self>

Source

pub fn from_void(vm: *mut c_void) -> Option<Self>

Source

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}
Source

pub fn attach(&self) -> Option<&'static JEnv>

Source

pub fn attach_as_daemon(&self) -> Option<&'static JEnv>

Source

pub fn detach(&self)

Source

pub fn env_with_version(&self, version: jint) -> Option<&'static JEnv>

Source

pub fn env(&self) -> Option<&'static JEnv>

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		}
Source

pub fn env_1_6(&self) -> Option<&'static JEnv>

Source

pub fn env_1_4(&self) -> Option<&'static JEnv>

Source

pub fn env_1_2(&self) -> Option<&'static JEnv>

Source

pub fn env_1_1(&self) -> Option<&'static JEnv>

Trait Implementations§

Source§

impl Clone for JVm

Source§

fn clone(&self) -> JVm

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for JVm

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for JVm

Source§

impl Send for JVm

Source§

impl Sync for JVm

Auto Trait Implementations§

§

impl Freeze for JVm

§

impl RefUnwindSafe for JVm

§

impl Unpin for JVm

§

impl UnwindSafe for JVm

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.