Function spacetimedb_cli::generate::rust::autogen_rust_globals

source ·
pub fn autogen_rust_globals(
    ctx: &GenCtx,
    items: &[GenItem]
) -> Vec<Vec<(String, String)>>
Expand description

Generate a mod.rs as the entry point into the autogenerated code.

The mod.rs contains several things:

  1. pub mod and pub use declarations for all the other files generated. Without these, either the other files wouldn’t get compiled, or users would have to mod-declare each file manually.

  2. enum ReducerEvent, which has variants for each reducer in the module. Row callbacks are passed an optional ReducerEvent as an additional argument, so they can know what reducer caused the row to change.

  3. struct Module, which implements SpacetimeModule. The methods on SpacetimeModule implement passing appropriate type parameters to various SDK internal functions.

  4. fn connect, which invokes spacetimedb_sdk::background_connection::BackgroundDbConnection::connect to connect to a remote database, and passes the handle_row_update and handle_event functions so the BackgroundDbConnection can spawn workers which use those functions to dispatch on the content of messages.