mirror of
https://github.com/hexedtech/jni-toolbox.git
synced 2024-11-22 07:24:53 +01:00
docs: updated readme
This commit is contained in:
parent
0580422abf
commit
8e53c475c2
1 changed files with 25 additions and 21 deletions
28
README.md
28
README.md
|
@ -32,8 +32,6 @@ impl<'j> IntoJavaObject for MyClass {
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pointers
|
### Pointers
|
||||||
To return pointer type values, add the `ptr` attribute.
|
|
||||||
|
|
||||||
Note that, while it is possible to pass raw pointers to the JVM, it is not safe by default and must be done with extreme care.
|
Note that, while it is possible to pass raw pointers to the JVM, it is not safe by default and must be done with extreme care.
|
||||||
|
|
||||||
### Exceptions
|
### Exceptions
|
||||||
|
@ -67,7 +65,7 @@ The following function:
|
||||||
```rust
|
```rust
|
||||||
#[jni(package = "mp.code", class = "Client", ptr)]
|
#[jni(package = "mp.code", class = "Client", ptr)]
|
||||||
fn connect(config: Config) -> Result<Client, ConnectionError> {
|
fn connect(config: Config) -> Result<Client, ConnectionError> {
|
||||||
tokio().block_on(Client::connect(config))
|
super::tokio().block_on(Client::connect(config))
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -76,15 +74,18 @@ generates a matching expanded function invoking it:
|
||||||
<details><summary>Show macro expansion</summary>
|
<details><summary>Show macro expansion</summary>
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
#[doc = " Connect using the given credentials to the default server, and return a [Client] to interact with it."]
|
||||||
|
fn connect(config: Config) -> Result<Client, ConnectionError> {
|
||||||
|
super::tokio().block_on(Client::connect(config))
|
||||||
|
}
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_unit)]
|
||||||
pub extern "system" fn Java_mp_code_Client_connect<'local>(
|
pub extern "system" fn Java_mp_code_Client_connect<'local>(
|
||||||
mut env: jni::JNIEnv<'local>,
|
mut env: jni::JNIEnv<'local>,
|
||||||
_class: jni::objects::JClass<'local>,
|
_class: jni::objects::JClass<'local>,
|
||||||
mut config: <Config as jni_toolbox::FromJava<'local>>::T,
|
config: <Config as jni_toolbox::FromJava<'local>>::From,
|
||||||
) -> <Client as jni_toolbox::IntoJava<'local>>::T {
|
) -> <Client as jni_toolbox::IntoJava<'local>>::Ret {
|
||||||
use jni_toolbox::{FromJava, IntoJava, JniToolboxError};
|
use jni_toolbox::{FromJava, IntoJava, JniToolboxError};
|
||||||
let mut env_copy = unsafe { env.unsafe_clone() };
|
|
||||||
let config_new = match jni_toolbox::from_java_static::<Config>(&mut env, config) {
|
let config_new = match jni_toolbox::from_java_static::<Config>(&mut env, config) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -98,7 +99,10 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
|
||||||
return std::ptr::null_mut();
|
return std::ptr::null_mut();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match connect(config_new) {
|
let mut env_copy = unsafe { env.unsafe_clone() };
|
||||||
|
let result = connect(config_new);
|
||||||
|
let ret = match result {
|
||||||
|
Ok(x) => x,
|
||||||
Err(e) => match env_copy.find_class(e.jclass()) {
|
Err(e) => match env_copy.find_class(e.jclass()) {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
$crate::panicking::panic_fmt($crate::const_format_args!(
|
$crate::panicking::panic_fmt($crate::const_format_args!(
|
||||||
|
@ -135,8 +139,9 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Ok(ret) => match ret.into_java(&mut env_copy) {
|
};
|
||||||
Ok(fin) => return fin,
|
match ret.into_java(&mut env_copy) {
|
||||||
|
Ok(fin) => fin,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = env_copy.throw_new(
|
let _ = env_copy.throw_new(
|
||||||
"java/lang/RuntimeException",
|
"java/lang/RuntimeException",
|
||||||
|
@ -145,9 +150,8 @@ pub extern "system" fn Java_mp_code_Client_connect<'local>(
|
||||||
res
|
res
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
return std::ptr::null_mut();
|
std::ptr::null_mut()
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in a new issue