-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy paths000_hello.rs
29 lines (26 loc) · 984 Bytes
/
s000_hello.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use jni::objects::{JClass, JString};
use jni::sys::jstring;
use jni::JNIEnv;
#[no_mangle]
pub extern "system" fn Java_sample_s000_HelloWorld_hello<'local>(
mut env: JNIEnv<'local>,
// This is the class that owns our static method. It's not going to be used,
// but still must be present to match the expected signature of a static
// native method.
_class: JClass<'local>,
input: JString<'local>,
) -> jstring {
// First, we have to get the string out of Java. Check out the `strings`
// module for more info on how this works.
let input: String = env
.get_string(&input)
.expect("Couldn't get java string!")
.into();
// Then we have to create a new Java string to return. Again, more info
// in the `strings` module.
let output = env
.new_string(format!("Hello, {}!", input))
.expect("Couldn't create java string!");
// Finally, extract the raw pointer to return.
output.into_raw()
}