mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-07-05 21:25:41 -04:00
3abaec9eaf
# Description of Changes Refactored the Rust SDK table trait surface into composable capabilities and updated Rust codegen to match. [Discord thread](https://discord.com/channels/1037340874172014652/1492137984902959164) ### Motivation The granular traits are a useful type-system cleanup on their own, but the main motivation is to let downstream integration crates like [bevy_stdb](https://github.com/onx2/bevy_stdb) express callback capabilities more directly instead of routing them through broader semantic categories. For example, `bevy_stdb` may want to support bindings like “forward only inserts from this subscribed view as Bevy messages” for a relation that is not semantically an `EventTable`. Today this can still be made to work with broader abstractions, so this is not primarily about enabling new runtime behavior. The value is mostly at compile time: more precise trait bounds, clearer downstream APIs, and better guarantees that a binding only requires the capabilities it actually uses. Concretely, this makes it easier for integration crates to model things like insert-only or delete-only bindings for ordinary tables or views without conflating those behaviors with `EventTable` semantics. Example: ```rust // Current semantic shape: plugin.add_event_table::<LogRow>(|reg, db| reg.bind(db.logs())); // Potential capability-based shape: plugin.add_insert_source::<CharacterRow>(|reg, db| reg.bind(db.characters_near_me())); plugin.add_delete_source::<CharacterRow>(|reg, db| reg.bind(db.characters_near_me())); ``` ### Summary - Added a shared `TableLike` trait for common table handle functionality: - `Row` - `EventContext` - `count` - `iter` - Added capability traits: - `WithInsert` - `WithDelete` - `WithUpdate` # API and ABI breaking changes None. This is additive only. # Expected complexity level and risk 2/5 This is additive but potential risks/complexity are that the surface area of the API is larger and there isn't really overlap between original approach and the additive. So maybe in usage we'll need to consider satisfying those new traits too? # Testing - [x] Ran `cargo check --manifest-path /Users/onx2/Documents/projects/SpacetimeDB/sdks/rust/Cargo.toml` - [x] Ran `cargo test --manifest-path /Users/onx2/Documents/projects/SpacetimeDB/Cargo.toml -p spacetimedb-codegen test_codegen_rust` - [x] Regenerated Rust client bindings using the workspace CLI and verified generated impls match the new trait structure - [ ] Reviewer: regenerate a Rust client with the workspace CLI and confirm the generated bindings compile cleanly --------- Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com> Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
This test client is used with the module sdk-test.
It is invoked by a majority of the SDK tests, and is responsible for testing that serialization, deserialization, type dispatch, and client-side callbacks work as expected.
To (re-)generate the module_bindings, from this directory, run:
mkdir -p src/module_bindings
spacetime generate --lang rust --out-dir src/module_bindings --module-path ../../../../modules/sdk-test