Skip to content

Commit

Permalink
Future cancellation docs and other minor doc tweaks. (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhammond authored Aug 7, 2024
1 parent 7ff7584 commit 33a24e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/manual/src/futures.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ Use `uniffi_set_event_loop()` to handle this case.
It should be called before the Rust code makes the async call and passed an eventloop to use.

Note that `uniffi_set_event_loop` cannot be glob-imported because it's not part of the library's `__all__`.

## Cancelling async code.

We don't directly support cancellation in UniFFI even when the underlying platforms do.
You should build your cancellation in a separate, library specific channel; for example, exposing a `cancel()` method that sets a flag that the library checks periodically.

Cancellation can then be exposed in the API and be mapped to one of the error variants, or None/empty-vec/whatever makes sense.
There's no builtin way to cancel a future, nor to cause/raise a platform native async cancellation error (eg, a swift `CancellationError`).

See also https://github.com/mozilla/uniffi-rs/pull/1768.
13 changes: 6 additions & 7 deletions docs/manual/src/tutorial/foreign_language_bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ The next step is to have UniFFI generate source code for your foreign language.

First, make sure you have installed all the [prerequisites](./Prerequisites.md).

Ideally you would then run the `uniffi-bindgen` binary from the `uniffi` crate to generate your bindings. However, this
is only available with [Cargo nightly](https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies).
To work around this, you need to create a binary in your project that does the same thing.
Ideally you would then run the `uniffi-bindgen` binary from the `uniffi` crate to generate your bindings,
but if not on [Cargo nightly](https://doc.rust-lang.org/cargo/reference/unstable.html#artifact-dependencies),
you need to create a binary in your project that does the same thing.

Add the following to your `Cargo.toml`:

Expand All @@ -32,11 +32,10 @@ You can now run `uniffi-bindgen` from your project using `cargo run --features=u

### Multi-crate workspaces

If your project consists of multiple crates in a Cargo workspace, then the process outlined above would require you
creating a binary for each crate that uses UniFFI. You can avoid this by creating a separate crate for running `uniffi-bindgen`:
- Name the crate `uniffi-bindgen`
In a multiple crates workspace, you can create a separate crate for running `uniffi-bindgen`:
- Name the crate `uniffi-bindgen`, add it to your workspace.
- Add this dependency to `Cargo.toml`: `uniffi = {version = "0.XX.0", features = ["cli"] }`
- Follow the steps from the previous section to add the `uniffi-bindgen` binary target
- As above, add the `uniffi-bindgen` binary target

Then your can run `uniffi-bindgen` from any crate in your project using `cargo run -p uniffi-bindgen [args]`

Expand Down
8 changes: 4 additions & 4 deletions docs/manual/src/udl/ext_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ namespace app {
```

Supported values:
* "enum", "trait", "callback", "trait_with_foreign"
* For records, either "record", "dictionary" or "struct"
* For objects, either "object", "impl" or "interface"
* Enums: `enum`
* Records: `record`, `dictionary` or `struct`
* Objects: `object`, `impl` or `interface`
* Traits: `trait`, `callback` or `trait_with_foreign`

eg:
```
typedef enum MyEnum;
typedef interface MyObject;
```
etc.

Note that in 0.28 and prior, we also supported this capability with a `[Rust=]` attribute.
This attribute is deprecated and may be removed in a later version.

0 comments on commit 33a24e6

Please sign in to comment.