kkprog

kkprog

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().

3 823 3

Marked As Solved

herbert

herbert

Author of Hands-on Rust

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.

Also Liked

herbert

herbert

Author of Hands-on Rust

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.

Popular Pragmatic Bookshelf topics Top

mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
22 1619 20
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
2 1179 3
New
New
digitalbias
Title: Build a Weather Station with Elixir and Nerves: Problem connecting to Postgres with Grafana on (page 64) If you follow the defau...
0 1931 4
New
dsmith42
Hey there, I’m enjoying this book and have learned a few things alredayd. However, in Chapter 4 I believe we are meant to see the “&gt;...
0 1914 3
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
1 2235 1
New
mert
AWDWR 7, page 152, page 153: Hello everyone, I’m a little bit lost on the hotwire part. I didn’t fully understand it. On page 152 @rub...
0 1224 4
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
1 1108 3
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
1 3334 6
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
3 1149 19
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1020 16977 374
New
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
11 5148 4
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
190 3669 79
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
81 3265 26
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
32 3094 9
New
New
PragmaticBookshelf
Author Spotlight: VM Brasseur @vmbrasseur We have a treat for you today! We turn the spotlight onto Open Source as we sit down with V...
16 3861 11
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
41 2599 20
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
1 1524 1
New

Latest in PragProg Customers

View all threads ❯