|
1 | 1 | # j4rs
|
2 | 2 |
|
3 | 3 | [](https://crates.io/crates/j4rs)
|
4 |
| -[](https://central.sonatype.com/artifact/io.github.astonbitecode/j4rs/) |
| 4 | +[](https://central.sonatype.com/artifact/io.github.astonbitecode/j4rs/) |
5 | 5 | 
|
6 | 6 |
|
7 | 7 | j4rs stands for __'Java for Rust'__ and allows effortless calls to Java code from Rust and vice-versa.
|
@@ -260,6 +260,14 @@ using an internal one-threaded `ScheduledExecutorService`.
|
260 | 260 |
|
261 | 261 | This has apparent performance issues.
|
262 | 262 |
|
| 263 | +#### `invoke_async` and `Send` |
| 264 | + |
| 265 | +`Instance`s are `Send` and can be safely sent to other threads. However, because of [Send Approximation](https://rust-lang.github.io/async-book/07_workarounds/03_send_approximation.html), the `Future` returned by `invoke_async` is _not_ `Send`, even if it just contains an `Instance`. This is because the `Jvm` is being captured by the `async` call as well and the `Jvm` is __not__ `Send`. |
| 266 | + |
| 267 | +In order to have a `Future<Instance>` that __is__ `Send`, the `Jvm::invoke_into_sendable_async` can be used. This function does not get a `Jvm` as argument; it creates one internally when needed and applies some scoping workarounds in order to achieve returning a `Future<Instance>` which is also `Send`. |
| 268 | + |
| 269 | +Discussion [here](https://github.com/astonbitecode/j4rs/issues/103). |
| 270 | + |
263 | 271 | ### Casting
|
264 | 272 |
|
265 | 273 | An `Instance` may be casted to some other Class:
|
@@ -446,7 +454,7 @@ The jar for `j4rs` is available in the Maven Central. It may be used by adding t
|
446 | 454 | <dependency>
|
447 | 455 | <groupId>io.github.astonbitecode</groupId>
|
448 | 456 | <artifactId>j4rs</artifactId>
|
449 |
| - <version>0.18.0</version> |
| 457 | + <version>0.19.0</version> |
450 | 458 | <scope>provided</scope>
|
451 | 459 | </dependency>
|
452 | 460 | ```
|
@@ -486,7 +494,7 @@ pub extern fn jni_onload(env: *mut JavaVM, _reserved: jobject) -> jint {
|
486 | 494 | Create an `Activity` and define your native methods normally, as described [here](#java-to-rust-support).
|
487 | 495 |
|
488 | 496 | Note:
|
489 |
| -If you encounter any issues when using j4rs in older Android versions, this may be caused by Java 8 compatibility problems. |
| 497 | +If you encounter any issues when using j4rs in older Android versions, this may be caused by Java 8 compatibility problems. |
490 | 498 | This is why there is a `Java 7` version of `j4rs`:
|
491 | 499 |
|
492 | 500 | ```xml
|
|
0 commit comments