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:
-
pub mod
andpub use
declarations for all the other files generated. Without these, either the other files wouldn’t get compiled, or users would have tomod
-declare each file manually. -
enum ReducerEvent
, which has variants for each reducer in the module. Row callbacks are passed an optionalReducerEvent
as an additional argument, so they can know what reducer caused the row to change. -
struct Module
, which implementsSpacetimeModule
. The methods onSpacetimeModule
implement passing appropriate type parameters to various SDK internal functions. -
fn connect
, which invokesspacetimedb_sdk::background_connection::BackgroundDbConnection::connect
to connect to a remote database, and passes thehandle_row_update
andhandle_event
functions so theBackgroundDbConnection
can spawn workers which use those functions to dispatch on the content of messages.