Rendering with Themes

The MapBuilder needs to know what theme you’re associating with your newly designed map. Open map_builder/mod.rs, and add a theme to the MapBuilder:

 const​ NUM_ROOMS: usize = 20;
 pub​ ​struct​ MapBuilder {
 pub​ map : Map,
 pub​ rooms : Vec<Rect>,
 pub​ monster_spawns : Vec<Point>,
 pub​ player_start : Point,
 pub​ amulet_start : Point,
 pub​ theme : Box<dyn MapTheme>
 }

If you’re using an IDE, it probably just highlighted all of your map builders as compilation errors. These errors happen because you’ve extended MapBuilder to include a new field. Rust requires that you initialize every field in a struct on creation—uninitialized fields are a common source of bugs ...

Get Hands-on Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.