← All Workshops

MudEngine Part 3: File-Based World Loading

Update main

The main function simplifies: instead of World::new(), we call World::from_file("game.toml"). Because from_file uses .expect() internally, main no longer needs a match on the result. Everything else — the REPL loop, command parsing, and output — is unchanged from Part 2.

mud-engine-repl/src/main.rs
fn main() {
    let mut world = World::from_file("game.toml");

    println!("=== MudEngine REPL ===\n");
    println!("World loaded from game.toml\n");
    println!("{}\n", world.look());
💡 Error handling

We use .expect() so the program panics with a clear error message if the file is missing or malformed. Try deleting game.toml or adding invalid TOML — expect tells you exactly what went wrong.