← All Workshops

MudEngine Part 4: Single-Player Dioxus GUI

Step 7 / 13

Wire up the module skeleton

Create the files that declare the module structure. main.rs becomes a thin entry point — it declares the two modules and launches the App component (which we will define in src/components/app.rs in a moment).

Replace the auto-generated src/main.rs with:

mud-engine/src/main.rs
mod components;
mod game;

use crate::components::app::App;

fn main() {
    dioxus::launch(App);
}
📁 The module declaration files

Create the module declaration files. Rust looks up a module named game in src/game.rs — this is the modern layout, where a directory module's root file sits next to the directory instead of inside it as mod.rs. From game.rs, Rust finds the module's own submodules in the sibling src/game/ directory.

src/components/ is the one exception: in Part 5 dx components add writes its library declarations into src/components/mod.rs, so that directory keeps the classic mod.rs name.

  • src/game.rs — declares the game-logic submodules
  • src/components/mod.rs — declares every Dioxus component file
mud-engine/src/game.rs
pub mod world;
mud-engine/src/components/mod.rs
pub mod app;
pub mod world_grid;
🔍 What the skeleton does
  • mod game; and mod components; tell Rust about our two top-level modules.
  • pub mod world; (in src/game.rs) exposes game::world.
  • pub mod app; pub mod world_grid; (in components/mod.rs) expose components::app and components::world_grid.

The pub keyword matters: a component in one file must be visible to a component in another file. App is used by main.rs (dioxus::launch(App)), and WorldGrid is used by App — so both need to be pub. We will see the same pub on the component functions themselves in the next steps.

Step 7 / 13