
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().
Marked As Solved

herbert
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
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








Modern front-end development for Rails, second edition - Struggling to get the first chapter to work


Other popular topics








Latest in PragProg Customers
Latest (all)
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /rails
- /js
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim