Commit 3abaec9
More granular table traits (#4775)
# 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>1 parent 03e1b13 commit 3abaec9
153 files changed
Lines changed: 6826 additions & 10 deletions
File tree
- crates
- bindings-typescript/case-conversion-test-client/src/module_bindings
- codegen
- src
- tests/snapshots
- sdks/rust
- src
- tests
- case-conversion-client/src/module_bindings
- connect_disconnect_client/src/module_bindings
- event-table-client/src/module_bindings
- procedural-view-pk-client/src/module_bindings
- procedure-client/src/module_bindings
- procedure-concurrency-client/src/module_bindings
- test-client/src/module_bindings
- view-client/src/module_bindings
- view-pk-client/src/module_bindings
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
186 | 194 | | |
187 | 195 | | |
188 | 196 | | |
| |||
203 | 211 | | |
204 | 212 | | |
205 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
206 | 229 | | |
207 | 230 | | |
208 | 231 | | |
| |||
213 | 236 | | |
214 | 237 | | |
215 | 238 | | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
216 | 247 | | |
217 | 248 | | |
218 | 249 | | |
| |||
246 | 277 | | |
247 | 278 | | |
248 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
249 | 310 | | |
250 | 311 | | |
251 | 312 | | |
| |||
272 | 333 | | |
273 | 334 | | |
274 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
275 | 351 | | |
276 | 352 | | |
277 | 353 | | |
| |||
0 commit comments