← All Workshops
MudEngine Part 3: File-Based World Loading
Step 8 / 8
Congratulations!
We decoupled the game world from the Rust source code. The REPL itself is unchanged — it still reads stdin and prints room descriptions — but the world data now lives in a plain-text game.toml file.
What we achieved:
- Data-driven design — rooms are defined in a config file, not hardcoded
- Id-based exits — exits reference rooms by numeric id, stable even if rooms are renamed
- Clear error messages — missing files and invalid exits produce helpful diagnostics
- Zero changes to the REPL loop — the engine is the same, only the data source changed
In Part 4 we lift this same engine into a Dioxus GUI — the world loads from game.toml on startup and renders a 3×3 grid in the browser, using the same movement commands.
📚 What we learned
| Concept | How we used it |
|---|---|
serde Deserialize | Derive the trait to parse TOML structs |
toml::from_str | Deserialize a &str into a Rust struct |
Numeric id on rooms | Each room has a stable unique id; exits reference rooms by id |
iter().find() for id lookup | Locate the current room by id instead of indexing into the Vec |
std::fs::read_to_string | Read the entire file into a String |
Result for fallible constructors | World::from_file returns Result<Self, String> instead of panicking |
Step 8 / 8