Checkers with the events plugin
Alice and Bob share a checkers board. A confirmed move must survive a restart, but a hand cursor only matters while someone watches it. Turn notifications and animation cues help the other player follow the game. The board remains the authority when a player misses a cue.
This tutorial connects those behaviors in one program, with a version for each high-level binding. Each step adds a different event exchange to the same game. Start with the quickstart if you have not opened a database or run a stored mutation.
Read the Go example, Rust example, Clojure example, Odin example or Python example. The next step also has language and document-format selectors.
The board
Starting position
Squares are the 32 playable dark squares, numbered 0–31 from top to bottom and left to right. Red moves toward larger square numbers. Black moves toward smaller numbers. No piece is a king in this position.
The game data starts with this board:
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 000 | 54 52 4F 4E | magic TRON |
| 004 | 4C 6B696E67 | txt "king" |
| 009 | 01 | bit false |
| 00A | 0F 0A 04000000 0900 0000 | map leaf, size 10: @4 → @9 |
| 014 | 6C 737175617265 | txt "square" |
| 01B | 02 0B000000000000 00 | i64 11 |
| 024 | 0F 0A 14000000 1B00 0000 | map leaf, size 10: @14 → @1B |
| 02E | 5C 636F6C6F72 | txt "color" |
| 034 | 3C 726564 | txt "red" |
| 038 | 0F 0A 2E000000 3400 0000 | map leaf, size 10: @2E → @34 |
| 042 | 07 12 08030000 0A00 0000 24000000 3800 0000 | map branch, size 18, depth 0 (root), slots 3, 8, 9: @A → @24 → @38 |
| 054 | 4C 6B696E67 | txt "king" |
| 059 | 01 | bit false |
| 05A | 0F 0A 54000000 5900 0000 | map leaf, size 10: @54 → @59 |
| 064 | 6C 737175617265 | txt "square" |
| 06B | 02 10000000000000 00 | i64 16 |
| 074 | 0F 0A 64000000 6B00 0000 | map leaf, size 10: @64 → @6B |
| 07E | 5C 636F6C6F72 | txt "color" |
| 084 | 3C 726564 | txt "red" |
| 088 | 0F 0A 7E000000 8400 0000 | map leaf, size 10: @7E → @84 |
| 092 | 07 12 08030000 5A00 0000 74000000 8800 0000 | map branch, size 18, depth 0 (root), slots 3, 8, 9: @5A → @74 → @88 |
| 0A4 | 4C 6B696E67 | txt "king" |
| 0A9 | 01 | bit false |
| 0AA | 0F 0A A4000000 A900 0000 | map leaf, size 10: @A4 → @A9 |
| 0B4 | 6C 737175617265 | txt "square" |
| 0BB | 02 08000000000000 00 | i64 8 |
| 0C4 | 0F 0A B4000000 BB00 0000 | map leaf, size 10: @B4 → @BB |
| 0CE | 5C 636F6C6F72 | txt "color" |
| 0D4 | 3C 726564 | txt "red" |
| 0D8 | 0F 0A CE000000 D400 0000 | map leaf, size 10: @CE → @D4 |
| 0E2 | 07 12 08030000 AA00 0000 C4000000 D800 0000 | map branch, size 18, depth 0 (root), slots 3, 8, 9: @AA → @C4 → @D8 |
| 0F4 | 4C 6B696E67 | txt "king" |
Show all 64 nodes
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 0F9 | 01 | bit false |
| 0FA | 0F 0A F4000000 F900 0000 | map leaf, size 10: @F4 → @F9 |
| 104 | 6C 737175617265 | txt "square" |
| 10B | 02 14000000000000 00 | i64 20 |
| 114 | 0F 0A 04010000 0B01 0000 | map leaf, size 10: @104 → @10B |
| 11E | 5C 636F6C6F72 | txt "color" |
| 124 | 5C 626C61636B | txt "black" |
| 12A | 0F 0A 1E010000 2401 0000 | map leaf, size 10: @11E → @124 |
| 134 | 07 12 08030000 FA00 0000 14010000 2A01 0000 | map branch, size 18, depth 0 (root), slots 3, 8, 9: @FA → @114 → @12A |
| 146 | 4C 72656433 | txt "red3" |
| 14B | 0F 0A 46010000 E200 0000 | map leaf, size 10: @146 → @E2 |
| 155 | 4C 72656437 | txt "red7" |
| 15A | 0F 0A 55010000 4200 0000 | map leaf, size 10: @155 → @42 |
| 164 | 4C 72656432 | txt "red2" |
| 169 | 0F 0A 64010000 9200 0000 | map leaf, size 10: @164 → @92 |
| 173 | 6C 626C61636B31 | txt "black1" |
| 17A | 0F 0A 73010000 3401 0000 | map leaf, size 10: @173 → @134 |
| 184 | 07 16 1A010000 4B01 0000 5A010000 6901 0000 7A010000 | map branch, size 22, depth 0 (root), slots 1, 3, 4, 8: @14B → @15A → @169 → @17A |
| 19A | 4C 67616D65 | txt "game" |
| 19F | 8C 636865636B6572 73 | txt "checkers" |
| 1A8 | 0F 0A 9A010000 9F01 0000 | map leaf, size 10: @19A → @19F |
| 1B2 | 8C 7265766973696F 6E | txt "revision" |
| 1BB | 02 00000000000000 00 | i64 0 |
| 1C4 | 0F 0A B2010000 BB01 0000 | map leaf, size 10: @1B2 → @1BB |
| 1CE | 07 0E 20010000 A801 0000 C4010000 | map branch, size 14, depth 1, slots 5, 8: @1A8 → @1C4 |
| 1DC | 6C 706965636573 | txt "pieces" |
| 1E3 | 0F 0A DC010000 8401 0000 | map leaf, size 10: @1DC → @184 |
| 1ED | 4C 7475726E | txt "turn" |
| 1F2 | 3C 726564 | txt "red" |
| 1F6 | 0F 0A ED010000 F201 0000 | map leaf, size 10: @1ED → @1F2 |
| 200 | 07 12 00850000 CE01 0000 E3010000 F601 0000 | map branch, size 18, depth 0 (root), slots 8, 10, 15: @1CE → @1E3 → @1F6 |
| 212 | 7C 235F7461626C65 | txt "#_table" |
| 21A | 0F 0A 12020000 0002 0000 | map leaf, size 10: @212 → @200 |
| Offset (hex) | Bytes (hex) | Meaning |
|---|---|---|
| 224 | 1A020000 00000000 | root → @21A; previous: none |
Red plays 11 → 15. Black then jumps 20 → 13 → 4, capturing red2 on 16 and red3 on 8. Each turn advances the board revision once. Pieces are a map keyed by piece ID, while a jump path is an ordered sequence.
The checkers/board query reads the current board. Both mutations check the expected revision, turn and complete position before they write. A rejected or repeated turn leaves the board unchanged.
Load the plugins
Follow Use a release to configure your binding, library and license. Keep the extracted release directory layout.
Open the database with both events and sdk enabled:
fn open_checkers(path: &str, sdk_directory: &str) -> Outcome<Database> {
Ok(stardust::open(
path,
&Options {
plugins: Some(serde_json::from_value(json!({
"events": {},
"sdk": {
"rust": {"dir": sdk_directory},
"debounce": {"#dur": "PT0.25S"},
"maxWait": {"#dur": "PT2S"},
},
}))?),
..Options::default()
},
)?)
}Pass the database path and a dedicated SDK output directory to this function.
A relative directory is relative to the process working directory.
The SDK plugin replaces the output directory's contents. Keep your application source and database elsewhere.
It writes typed APIs automatically at open and after stored queries, mutations or event schemas change.
The debounce setting groups changes after 250 milliseconds without another definition commit.
The maxWait setting limits this scheduling delay to two seconds after the first change.
See the SDK reference for generation status and package imports.
The release includes generated SDK sources for these stored definitions. Each example imports those sources and uses their typed publishing, subscription, caller and worker helpers. Its database and SDK output use temporary directories that it removes when it ends. For your application, choose persistent paths. Generate the SDK after installing your definitions, then import its package in your application.
Follow the game
| Step | Behavior | What stays in the database |
|---|---|---|
| Pub/sub | Share hand cursors and announce turns | No cursor or notification messages |
| Request | Submit one move and receive one result | The accepted move and new turn |
| Pull | Receive legal landings as a stream | No exchange messages |
| Push | Submit the ordered jumps of one turn | The complete accepted turn |
| Duplex | Exchange drag positions and move previews | No draft positions |
The example starts in the middle of a game and checks two specific turns. Its game data contains legal candidates and stored mutations for those positions. This keeps the code focused on event coordination. A complete game would replace those definitions with its checkers rules.
Alice, Bob and the rules worker run inside one process and share one open database. The program seeds the board and stores definitions before creating their owners. An owner groups temporary coordination resources for cleanup. The example alternates their operations so you can see both ends of each exchange. A browser client would need an application transport to reach this process.
Files in the release
After extracting the release, use these paths relative to its root:
- Program:
abi/examples/checkers/rust/src/main.rs - Generated SDK:
abi/examples/checkers/rust/src/sdk - Game data:
abi/examples/checkers/checkers.dust
The game data file supplies the starting board, legal-move candidates, stored queries, mutations, event schemas and expected final board. The program reads it to prepare and verify the example.
Run the example
Run from the extracted release root in a POSIX shell. These commands read the DUST game data included in the release. The page format selector changes the displayed values. The program checks each exchange and prints the final board in DUST.
cargo run --locked --manifest-path abi/examples/checkers/rust/Cargo.toml -- abi/examples/checkers/checkers.dust dustShare hand cursors to begin the exchanges.