← All Workshops
MudEngine Part 7: Save & Load
Step 7 / 17
Create the persistence module
Up to now the game logic has lived across main.rs and a handful of files. Part 7 adds persistence — TOML parsing, runtime state types, and load/save functions — and those belong in their own module.
We'll build up src/game/persistence.rs over the next two steps. First, register the module in the index so the compiler knows it exists — add this line to src/game.rs:
mud-engine/src/game.rs
pub mod messages; pub mod random_name; pub mod room_data; pub mod server; pub mod persistence;
🔍 Module layout after this step
src/
├── main.rs ← entry point (unchanged)
├── game.rs ← module index
├── game/
│ ├── messages.rs ← PlayerInfo, ServerMessage, …
│ ├── room_data.rs ← static room data (replaced by Game.toml)
│ ├── persistence.rs ← NEW — TOML types + persistence
│ └── server.rs ← WebSocket endpoint + srv statics
└── components/
└── ...
The persistence module keeps all persistence logic in one place: TOML serde types, the runtime GameState, and the load_world() / load_players() / save_players() / can_move() functions. Other modules import only what they need via use super::persistence::*.
Step 7 / 17