Hands-on Rust: Rust newbie feedback: mod keyword (page 78)

I’m new to Rust; this is probably already well understood by others, but it tripped me up.

On page 78 (PDF) and in this block in particular:

mod map; // (1)

pub mod prelude { // (2)
    pub use bracket_lib::prelude::*; // (3)
    pub const SCREEN_WIDTH: i32 = 80; // (4)
    pub const SCREEN_HEIGHT: i32 = 50;
    pub use crate::map::*; // (5)
}

use prelude::*; // (6)

I’m left questioning whether pub mod prelude appends to the map namespace imported by the earlier mod map statement or if it sets up a new namespace specific to the current file. I will re-read this section a few more times before researching further.

Refs: http://media.pragprog.com/titles/hwrust/code/BasicDungeonCrawler/dungeon_crawl_map/src/main.rs

Sharing this feedback in case it is helpful in some way.

2 Likes