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 - application does not start after run bin/setup (page xviii)
Modern front-end development for Rails, second edition - Struggling to get the first chapter to work
Other popular topics
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /rails
- /js
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /html
- /centos
- /php
- /zig
- /deepseek
- /scala
- /textmate
- /sublime-text
- /lisp
- /react-native
- /nixos
- /debian
- /agda
- /kubuntu
- /arch-linux
- /django
- /deno
- /revery
- /ubuntu
- /manjaro
- /spring
- /nodejs
- /diversity
- /lua
- /julia
- /slackware
- /c






