@@ -65,7 +65,7 @@ spacetime build
6565
6666To the top of ` spacetimedb/src/lib.rs ` , add some imports we'll be using:
6767
68- ``` rust
68+ ``` rust server
6969use spacetimedb :: {table, reducer, Table , ReducerContext , Identity , Timestamp };
7070```
7171
@@ -86,7 +86,7 @@ For each `User`, we'll store their `Identity`, an optional name they can set to
8686
8787To ` spacetimedb/src/lib.rs ` , add the definition of the table ` User ` :
8888
89- ``` rust
89+ ``` rust server
9090#[table(name = user, public)]
9191pub struct User {
9292 #[primary_key]
@@ -100,7 +100,7 @@ For each `Message`, we'll store the `Identity` of the user who sent it, the `Tim
100100
101101To ` spacetimedb/src/lib.rs ` , add the definition of the table ` Message ` :
102102
103- ``` rust
103+ ``` rust server
104104#[table(name = message, public)]
105105pub struct Message {
106106 sender : Identity ,
@@ -119,7 +119,7 @@ It's also possible to call `set_name` via the SpacetimeDB CLI's `spacetime call`
119119
120120To ` spacetimedb/src/lib.rs ` , add:
121121
122- ``` rust
122+ ``` rust server
123123#[reducer]
124124/// Clients invoke this reducer to set their user names.
125125pub fn set_name (ctx : & ReducerContext , name : String ) -> Result <(), String > {
@@ -143,7 +143,7 @@ For now, we'll just do a bare minimum of validation, rejecting the empty name. Y
143143
144144To ` spacetimedb/src/lib.rs ` , add:
145145
146- ``` rust
146+ ``` rust server
147147/// Takes a name and checks if it's acceptable as a user's name.
148148fn validate_name (name : String ) -> Result <String , String > {
149149 if name . is_empty () {
@@ -160,7 +160,7 @@ We define a reducer `send_message`, which clients will call to send messages. It
160160
161161To ` spacetimedb/src/lib.rs ` , add:
162162
163- ``` rust
163+ ``` rust server
164164#[reducer]
165165/// Clients invoke this reducer to send messages.
166166pub fn send_message (ctx : & ReducerContext , text : String ) -> Result <(), String > {
@@ -179,7 +179,7 @@ We'll want to validate messages' texts in much the same way we validate users' c
179179
180180To ` spacetimedb/src/lib.rs ` , add:
181181
182- ``` rust
182+ ``` rust server
183183/// Takes a message's text and checks if it's acceptable to send.
184184fn validate_message (text : String ) -> Result <String , String > {
185185 if text . is_empty () {
@@ -203,7 +203,7 @@ We'll use `ctx.db.user().identity().find(ctx.sender)` to look up a `User` row fo
203203
204204To ` spacetimedb/src/lib.rs ` , add the definition of the connect reducer:
205205
206- ``` rust
206+ ``` rust server
207207#[reducer(client_connected)]
208208// Called when a client connects to a SpacetimeDB database
209209pub fn client_connected (ctx : & ReducerContext ) {
@@ -225,7 +225,7 @@ pub fn client_connected(ctx: &ReducerContext) {
225225
226226Similarly, whenever a client disconnects, the database will run the ` #[reducer(client_disconnected)] ` reducer if it's defined. By convention, it's named ` client_disconnected ` . We'll use it to un-set the ` online ` status of the ` User ` for the disconnected client.
227227
228- ``` rust
228+ ``` rust server
229229#[reducer(client_disconnected)]
230230// Called when a client disconnects from SpacetimeDB database
231231pub fn identity_disconnected (ctx : & ReducerContext ) {
0 commit comments