Skip to content

More granular table traits#4775

Merged
clockwork-labs-bot merged 11 commits into
clockworklabs:masterfrom
onx2:onx2/table-traits
Jun 30, 2026
Merged

More granular table traits#4775
clockwork-labs-bot merged 11 commits into
clockworklabs:masterfrom
onx2:onx2/table-traits

Conversation

@onx2

@onx2 onx2 commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

Refactored the Rust SDK table trait surface into composable capabilities and updated Rust codegen to match. Discord thread

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 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:

// 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

  • Ran cargo check --manifest-path /Users/onx2/Documents/projects/SpacetimeDB/sdks/rust/Cargo.toml
  • Ran cargo test --manifest-path /Users/onx2/Documents/projects/SpacetimeDB/Cargo.toml -p spacetimedb-codegen test_codegen_rust
  • 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

@onx2 onx2 marked this pull request as draft April 10, 2026 14:11
@onx2 onx2 changed the title updates More granular table traits Apr 10, 2026
Comment thread sdks/rust/src/table.rs
Comment thread crates/codegen/src/rust.rs
Comment thread crates/codegen/src/rust.rs Outdated
Comment thread sdks/rust/src/table.rs
@cloutiertyler

Copy link
Copy Markdown
Contributor

I see the Discord thread, but could you expand on what the motivation for this is in the PR description? An example of what this enables would be helpful.

@onx2

onx2 commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

I see the Discord thread, but could you expand on what the motivation for this is in the PR description? An example of what this enables would be helpful.

Updated 😄

@cloutiertyler

Copy link
Copy Markdown
Contributor

Is there any way to support this functionality without a breaking change? We only do breaking changes at major version boundaries.

@onx2 onx2 force-pushed the onx2/table-traits branch from 2026baf to 8171276 Compare May 16, 2026 17:33
@onx2

onx2 commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

Is there any way to support this functionality without a breaking change? We only do breaking changes at major version boundaries.

@cloutiertyler I think the new version should work without breaking changes b/c its only adding new capability traits instead of basing the previous table traits off of them.

@onx2

onx2 commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Is there anything I can do to help get this through the door? Any issues or concerns I can address? I normally wouldn't make a stink of waiting for a review but it has been over 2 months now 😅

@gefjon gefjon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. Sorry for the long delay on review; I've been on vacation for a bit.

@bfops bfops enabled auto-merge June 29, 2026 15:52
@bfops bfops disabled auto-merge June 30, 2026 02:20
@clockwork-labs-bot clockwork-labs-bot added this pull request to the merge queue Jun 30, 2026
Merged via the queue into clockworklabs:master with commit 3abaec9 Jun 30, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants