Title: Hands-on Rust: map_idx causes error E0425(page 81)

The call to map_idx on the render function of map (let idx = map_idx(x, y) ; ) caused error ‘error[E0425]: cannot find function map_idx in this scope’ when building the Dungeon Crawl program for the very first time.

Fixed it by referring to ithe function as Self::map_idx(x, y) based on a Stack Overflow thread.

Also on page 81 when the map field is added to the State struct the second parameter previously passed as State { } to main_loop had to be changed to State::new().

1 Like

Thanks for finding that! I’ve added the issues into the issue tracker and will have them resolved for the next beta.

Does the version in the downloadable code folder compile ok for you? It builds correctly on my system. I suspect that the book needs to be more explicit about where the map_idx function goes. It isn’t part of the Map implementation - it is a free function. From the map.rs file:

#[derive(Copy, Clone, PartialEq)]
pub enum TileType {
    Wall,
    Floor,
}

pub fn map_idx(x: i32, y: i32) -> usize {
    ((y * SCREEN_WIDTH) + x) as usize
}

pub struct Map {
    pub tiles: Vec<TileType>,
}

impl Map {
    pub fn new() -> Self {
    // etc.

Thanks again. The errata I’m receiving are great, and are really helping the book shape up.

1 Like

Hi Herbert,

I am reading the book and typing the code for practice. I have not downloaded the code. I feel like I won’t understand what I am doing if I simply download and run the code.

Yes, I suspected that something I did caused this error and only I seem to have encountered this error because others who seem to be further along (I see some errata for chapter 6) had not raised this as an error. I figured you’d take one look at this and identify where the issue was. Thank you for the lesson :).

Thanks,
Kris

Looking at the wording that introduces map_idx, it could definitely be clearer where it goes. So thank you - I’ll make sure it’s more obvious.

1 Like