spacetimedb-rust

Author deterministic WebAssembly server modules for SpacetimeDB in Rust.

25.0k|1.0k|Updated Jun 17, 2023
One-click install
npx skills add https://github.com/clockworklabs/SpacetimeDB --skill spacetimedb-rust
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: spacetimedb-rust
Source: https://github.com/clockworklabs/SpacetimeDB/tree/main/skills/spacetimedb-rust
Command: npx skills add https://github.com/clockworklabs/SpacetimeDB --skill spacetimedb-rust

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill guides developers to author correct, deterministic WebAssembly server modules for SpacetimeDB using Rust, reducing runtime errors and misuses of the SpacetimeDB 2.0 API surface such as incorrect table attributes, mutable reducer contexts, or unsafe side effects.

Core Features & Use Cases

  • Table and Index Patterns: Clear guidance for declaring tables, primary keys, auto-increment, and single- or multi-column indexes so data is stored and queried correctly.
  • Reducer and Procedure Rules: Rules for writing reducers with an immutable ReducerContext, deterministic RNG usage via ctx.rng(), safe error handling via Result, and when to use procedures for network I/O.
  • Lifecycle, Scheduled, and Event Patterns: Examples for init, client connect/disconnect, scheduled reducers, and event tables with on_insert subscription patterns.
  • Operational Best Practices: Transactional semantics, no global state, no filesystem/network in reducers, CLI build/publish commands, and common pitfalls to avoid.

Quick Start

Create a new Rust module that defines a public table and at least one reducer, build it with the spacetime CLI, and publish it to your target database.

Frequently Asked Questions about spacetimedb-rust

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write deterministic WebAssembly modules for SpacetimeDB in Rust?

To write deterministic SpacetimeDB modules in Rust, define public tables and reducers with an immutable ReducerContext, use ctx.rng() for random numbers, and avoid filesystem or network side effects to ensure transactional safety.

Why does my SpacetimeDB reducer fail when trying to mutate the context?

SpacetimeDB reducers require an immutable ReducerContext to maintain deterministic execution. Mutating the context or introducing global state, filesystem access, or network I/O inside reducers breaks transactional safety and causes runtime failures.

Can I use scheduled tasks and lifecycle events in a Rust SpacetimeDB module?

Yes, you can implement lifecycle patterns like init, client connect/disconnect, and scheduled reducers in Rust SpacetimeDB modules, alongside event tables with on_insert subscription patterns for event-driven game server workflows.

What's the best way to declare tables and indexes in a SpacetimeDB Rust module?

Declare tables with correct attributes for primary keys and auto-increment, then add single- or multi-column indexes to ensure data is stored and queried correctly within the SpacetimeDB 2.0 runtime.

Do I need the SpacetimeDB CLI to build and publish Rust modules?

Yes, you need the spacetime CLI to build your Rust WebAssembly module and publish it to your target SpacetimeDB database, ensuring compatibility with the 2.0+ API surface and deterministic runtime requirements.

When should I use procedures instead of reducers in SpacetimeDB?

Use SpacetimeDB procedures when you need network I/O capabilities, and use reducers for deterministic state transitions with safe error handling via Result, adhering to the transactional semantics of the SpacetimeDB runtime.