| Crates.io | turbo-genesis-macros |
| lib.rs | turbo-genesis-macros |
| version | 1.0.0 |
| created_at | 2025-06-27 15:22:25.828652+00 |
| updated_at | 2025-07-30 19:20:03.048236+00 |
| description | Turbo Genesis SDK Macros |
| homepage | |
| repository | https://github.com/super-turbo-society/turbo-genesis-sdk/tree/main/turbo-genesis-macros |
| max_upload_size | |
| id | 1728833 |
| size | 78,285 |
Procedural macros for the TurboGenesis game runtime. These macros reduce boilerplate and expose intuitive annotations for defining game state, commands, channels, and program metadata compiled to WebAssembly.
#[game]Creates a WASM entrypoint with hot-reload support and runtime state persistence. Applies #[turbo::serialize] and generates:
#[no_mangle] pub extern "C" fn run() symbol#[game]
pub struct MyGame {
tick: u32,
}
impl MyGame {
pub fn new() -> Self { Self { tick: 0 } }
pub fn update(&mut self) { self.tick += 1; }
}
Requirements:
fn new() -> Selffn update(&mut self)BorshSerialize + BorshDeserialize#[serialize]Applies BorshSerialize, BorshDeserialize, serde::Serialize, and serde::Deserialize to structs and enums.
#[serialize]
struct SaveData {
level: u8,
items: Vec<String>,
}
#[command(name = "foo")]Registers a struct or enum as a Turbo command callable from clients. Adds:
exec() method for client invocation#[command(name = "greet")]
struct GreetCommand { user: String }
impl CommandHandler for GreetCommand {
fn run(&mut self, user_id: &str) -> Result<(), std::io::Error> { ... }
}
#[channel(name = "chat")]Defines a duplex WebSocket-style handler for Turbo's channel system. Provides:
subscribe() method for clients#[channel(name = "chat")]
struct ChatHandler;
impl ChannelHandler for ChatHandler {
type Send = ChatLog;
type Recv = ChatMessage;
fn on_connect(&mut self, user_id: &str) { ... }
fn on_data(&mut self, user_id: &str, msg: ChatMessage) { ... }
fn on_interval(&mut self) { ... }
fn on_close(&mut self) { ... }
}
#[program]Declares a module as a Turbo program, injects runtime constants, and calculates a stable program ID using the user UUID.
[package.metadata.turbo]
user = "<uuid>"
#[program]
mod my_game {
// Now contains PROGRAM_ID, PROGRAM_NAME, etc.
}
Injects:
PROGRAM_NAME, PROGRAM_ID, PROGRAM_OWNERwatch(path) to observe reactive file changesMIT License. See LICENSE.