← All Workshops

MudEngine Part 3: File-Based World Loading

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
ConceptHow we used it
serde DeserializeDerive the trait to parse TOML structs
toml::from_strDeserialize a &str into a Rust struct
Numeric id on roomsEach room has a stable unique id; exits reference rooms by id
iter().find() for id lookupLocate the current room by id instead of indexing into the Vec
std::fs::read_to_stringRead the entire file into a String
Result for fallible constructorsWorld::from_file returns Result<Self, String> instead of panicking