You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows you to define an asynchronous `main` function instead of the
poll based `update` function, which allows you to more easily keep state
between individual ticks of the runtime. Unfortunately the most
efficient implementation isn't possible yet on stable Rust, as we are
blocked by the following two features:
- [`type_alias_impl_trait`](rust-lang/rust#63063)
- [`const_async_blocks`](rust-lang/rust#85368)
For now we have to use a workaround that is less efficient by calling
the `main` function at runtime and allocating it onto a new WebAssembly
page.
Here is a full example of how an auto splitter could look like using the
`async_main` macro:
Usage on stable Rust:
```rust
async_main!(stable);
```
Usage on nightly Rust:
```rust
async_main!(nightly);
```
The asynchronous main function itself:
```rust
async fn main() {
// TODO: Set up some general state and settings.
loop {
let process = Process::wait_attach("explorer.exe").await;
process.until_closes(async {
// TODO: Load some initial information from the process.
loop {
// TODO: Do something on every tick.
next_tick().await;
}
}).await;
}
}
```
Copy file name to clipboardExpand all lines: README.md
+91-4Lines changed: 91 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,34 @@
1
1
# <imgsrc="https://raw.githubusercontent.com/LiveSplit/LiveSplit/master/LiveSplit/Resources/Icon.png"alt="LiveSplit"height="42"width="45"align="top"/> asr
2
2
3
-
Helper crate to write auto splitters for LiveSplit One's auto splitting runtime.
4
3
5
-
## Example
4
+
Helper crate to write auto splitters for LiveSplit One's auto splitting
5
+
runtime.
6
+
7
+
There are two ways of defining an auto splitter.
8
+
9
+
## Defining an `update` function
10
+
11
+
You can define an `update` function that will be called every frame. This is
12
+
the simplest way to define an auto splitter. The function must have the
13
+
following signature:
14
+
```rust
15
+
#[no_mangle]
16
+
pubextern"C"fnupdate() {}
17
+
```
18
+
19
+
The advantage of this approach is that you have full control over what
20
+
happens on every tick of the runtime. However, it's much harder to keep
21
+
state around as you need to store all state in global variables as you need
0 commit comments