Errata

Programming Rust

Errata for Programming Rust

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
ePub
Page n/a
text

Current Copy:
well. If the right number of arguments is present, we putt them in an Arguments struct, and return it. Then we’ll...

Suggested:
"we putt them in an Arguments struct," should be "we put them in an Arguments struct,"





Anonymous  Sep 09, 2021  Nov 05, 2021
ePub
Page n/a
text

Current Copy:
square root of two. When searching the documentation, remember that there pages for both the types themselves, named “f32 (primitive type)” and

Suggested:
should be "remember that there are pages for both the types themselves,"

Anonymous  Sep 09, 2021  Nov 05, 2021
Page ?
Chapter 13 "Utility Traits"

Chapter 13 "Utility Traits" has following sentence:
"Vec<T> and [T: N] implement Borrow<[T]>."

I believe it should be `[T; N]` (semicolon instead of colon).

Note from the Author or Editor:
On page 320, in "Borrow and BorrowMut", we claim that "Vec<T> and [T: N] implement Borrow<[T]>."

The punctuation in "[T: N]" is incorrect. It should be "[T; N]", with a semicolon, not a colon.

Sergei Shirokov  Oct 25, 2021 
Page n/a
text

Typo:

Current Copy:
By using fn pointers in functions that take callbacks, you can restrict a caller to use only these noncapturing closures, gaining some perfomance and flexibility within the code using callbacks at the cost of flexibility for the users of your API.

Suggested:
"gaining some perfomance and flexibility" should be "gaining some performance and flexibility"

Note from the Author or Editor:
On page 345, we referred to "perfomance" gains from using function pointers. That was a spelling error. We meant "performance".

Anonymous  Jan 04, 2022 
Page page 706
near bottom (index)

RefCell type, borrow methid

(instead of method)

Note from the Author or Editor:
The index entry should read "borrow method", not "borrow methid".

Tom  Sep 08, 2022 
Page Expressions Chapter 6, Loops section
Very end of loops section

let strings: Vec<String> = error_messages();

is not declared mutable. Later used as:

for rs in &mut strings { ......

the point at hand was clearly demonstrated. But minor error nevertheless

Note from the Author or Editor:
Naaol is correct. The last code block in the section should have an extra line, showing the vector declared as mut:

let mut strings = error_messages();
for rs in &mut strings { // the type of rs is &mut String
rs.push('\n'); // add a newline to each string
}

Naaol Shupare  Jun 02, 2023 
Printed
Page "Debugging Macros", p. 610
First paragraph

The book says to add "-Z unstable-options --pretty expanded" to the rustc command line.

This used to work, but it doesn't anymore. The option is now spelled "-Z unstable-options -Z unpretty=expanded".

Alternatively, "cargo install cargo-expand" installs a new cargo subcommand that does this for you: "cargo expand".

Jason Orendorff
 
Apr 05, 2024 
Printed
Page "Doc-Tests", p. 202
First paragraph

Near the end of the section on doc-tests, the book says:

> If the code isn't even expected to compile, use `ignore` instead of `no_run`.

This is a mistake because "ignored" tests are only ignored by default. If you do `cargo test --ignored`, Cargo runs them all. The non-compiling code will then fail.

Probably the best thing to do is mark fake Rust code that isn't expected to compile as "text".

Jason Orendorff
 
Apr 05, 2024 
Chapter 3. Expressions > Why Rust Has loop > 11th Paragraph

std::process:exit() -> std::process::exit()

Note from the Author or Editor:
Change "std::process:exit()" to "std::process::exit()" (adding one colon) in the Expressions chapter.

Sungmann Cho  Sep 06, 2020  Jun 11, 2021
Chapter 2 Safari
Chapter 2

In chapter 2 under "Concurrent Mandelbrot Program", it says:

To use it, we must add the following line to our Cargo.toml file:

crossbeam = "0.2"

but then later when it shows the whole Cargo.toml it shows 0.8:

[dependencies]
num = "0.4"
image = "0.13"
crossbeam = "0.8"

Note from the Author or Editor:
This has been corrected.

Vince  May 12, 2021  Jun 11, 2021
preface
Navigating This Book, 4th paragraph

The paragraph describes the remaining chapters of the book but omits chapter 20 on asynchronous programming.

Note from the Author or Editor:
This has been fixed.

Anonymous  May 23, 2021  Jun 11, 2021
Chapter 2
6th code block in "A Concurrent Mandelbrot Program"

The crossbeam dependency is added with version constraint = "0.2", this leads to a compilation error, because the closure to spawner.spawn has 0 arguments in crossbeam 0.2, but the code is written for crossbeam 0.8 which expects 1 argument.

Note from the Author or Editor:
Fixed in current text.

Joeri Samson  May 25, 2021  Jun 11, 2021
Chapter 2
First code block for "Mapping from Pixels to Complex Numbers"

The test for pixel_to_point uses a size where bounds.0 and bounds.1 are both 100, and the width and height are both 2. The result is that this test passes when a copy/paste error leads to code like this: ` im: upper_left.im - pixel.1 as f64 * height / bounds.0 as f64`, it also passes when you would use the width instead of height in that formula, but that's more likely to become a warning because height would be unused in pixel_to_point.

A test that catches this might be something like:
assert_eq!(pixel_to_point((100, 200), (25, 150),
Complex { re: -1.0, im: 0.0 },
Complex { re: 1.0, im: -1.0 }),
Complex { re: -0.5, im: -0.75 });

Which catches both of these separately and both of these made together.

Note from the Author or Editor:
This is a great suggestion. I think you meant (25, 175). I'll see if we can squeeze this in.

Joeri Samson  May 25, 2021  Jun 11, 2021
Printed
Page 20
Last paragraph, 1st sentence

“401 BAD REQUEST” => “400 BAD REQUEST”

xehpuk  Jul 31, 2021  Nov 05, 2021
Page 33
2nd code block

In the write_image fn, there's a call of encoder.encode with &pixels als the 1st param. pixels is already a slice, so no need to borrow (clippy::needless_borrow).

Note from the Author or Editor:
On page 33, in "Writing Image Files", in the code of `fn write_image`, we originally wrote `encoder.encode(&pixels, ...)`. The `&` is superfluous because `pixels` is already a reference.

The first argument should be simply `pixels`, not `&pixels`.

xehpuk  Aug 02, 2021 
Page 45
code block, middle of page

When attempting to write the output, if an error occurs the message contains args.filename, which is the input file, not the output file.

match fs::write(&args.output, &data) {
Ok(_) => {},
Err(e) => {
eprintln!("{} failed to write to file '{}': {:?}", "Error:".red().bold(), args.filename, e);
std::process::exit(1);
}
};

should instead be

match fs::write(&args.output, &data) {
Ok(_) => {},
Err(e) => {
eprintln!("{} failed to write to file '{}': {:?}", "Error:".red().bold(), args.output, e);
std::process::exit(1);
}
};

Note from the Author or Editor:
On page 45, in the large code block showing `fn main`, there are two similar `eprintln!()` statements that report errors. Each one includes a filename in the error message, but the second prints the wrong filename.

The use of `args.filename` that appears after the call to `fs::write(&args.output, &data)` is incorrect. It should be `args.output` instead. We regret the error.

Andrew Ring  Jan 19, 2022 
Page 47
code block, upper half of page

When attempting to write the output, if an error occurs the message contains args.filename, which is the input file, not the output file.

eprintln!("{} failed to write to file '{}': {:?}", "Error:".red().bold(), args.filename, e);

should instead be

eprintln!("{} failed to write to file '{}': {:?}", "Error:".red().bold(), args.output, e);

Note from the Author or Editor:
On page 47, the first line of the page mentions `args.filename`. This is the wrong filename. It should be `args.output` instead.

Andrew Ring  Jan 19, 2022 
Page 60
5th paragraph

Hello!

In the fifth paragraph on page 60, there is the first sentence:

"When searching the documentation, remember there pages ..."

Which is missing an 'are', as it should be:

"When searching the documentation, remember there are pages ..."

That's it. I'm liking the book very much, thanks!

Note from the Author or Editor:
On page 60, we wrote "remember that there pages".

It should say "remember that there are pages".

Kris van Rens  Dec 08, 2021 
PDF
Page 60
7th paragraph

“f64 (primitive type) => “f64 (primitive type)"

Sungmann Cho  Jun 28, 2021  Nov 05, 2021
Printed
Page 73
3rd paragraph, 1st sentence

“String literals” (two spaces) => “String literals”

xehpuk  Aug 03, 2021  Nov 05, 2021
Printed
Page 134
Precedence and Associativity, first sentence

"Table 6-1 summarizes of Rust expression syntax." => "Table 6-1 summarizes Rust's expression syntax."

Anonymous  Aug 15, 2021  Nov 05, 2021
Printed
Page 152
Assignment, third paragraph

"The full list is given in Table 6-1, at the end of this chapter", but the table starts on page 135 at the beginning of the chapter.

Anonymous  Aug 15, 2021  Nov 05, 2021
Printed
Page 163
println!() code block

“failed to lookup” => “failed to look up”

xehpuk  Aug 07, 2021  Nov 05, 2021
Page 178
last paragraph

two functions in this example -> three functions in this example

Note from the Author or Editor:
On page 178, in "Modules", the text refers to "the two functions in this example". A careful count of the functions in the example reveals that there are three of them. The text should say "the three functions in this example".

Sungmann Cho  Aug 23, 2021 
Page 196
1st paragraph

Instead of
`cargo test -- --no-capture`
it should be
`cargo test -- --nocapture`

See `cargo test -- --help`

Note from the Author or Editor:
On page 196, the command-line option that causes Cargo not to capture test output is incorrect. We wrote "--no-capture". The correct option is "--nocapture". There is no hyphen between "no" and "capture".

Martin  Nov 06, 2022 
PDF
Page 249
8th paragraph

iit's unpacking -> it's unpacking

Sungmann Cho  Jun 28, 2021  Nov 05, 2021
PDF
Page 263
1st paragraph

tthe -> the

Sungmann Cho  Jul 01, 2021  Nov 05, 2021
Page 266
Last sentence

I don't understand the meaning of the sentence. It's exactly the same syntax as used in the example above, with `str` instead of `char`.

Note from the Author or Editor:
On page 269, in "Traits and Other People's Types", we wrote "Of course, you can add this trait to types, too, ...". A word is missing in that sentence; it should begin "Of course, you can add this trait to other types, too, ...".

xehpuk  Aug 22, 2021 
Page 270
1st paragraph, 2nd sentence

The sentence says that `Creature` is a subtrait and supertrait of `Visible`, while the latter is the supertrait.

Note from the Author or Editor:
On page 270, in "Subtraits", we wrote: "...we say that `Creature` is a subtrait of `Visible`, and that `Creature` is `Visible`’s supertrait."

The second half of the sentence should say, "...and that `Visible` is `Creature`'s supertrait." We got it backwards.

xehpuk  Aug 22, 2021 
Page 378
Code block in try_fold and try_rfold section

While not a compile error, this line has an unnecessary ‘&’ reference:

Ok(sum + u64::from_str(&line?.trim())?)

This probably should be:

Ok(sum + u64::from_str(line?.trim())?)

Note from the Author or Editor:
Yes, the `&` in that line of code is superfluous and should be removed:

Ok(sum + u64::from_str(line?.trim())?)

Pete Kazmier  Sep 13, 2021 
Page 402
slice.rsplit(is_sep), slice.rsplit_mut(is_sep)

The description for these methods refers to slice and slice_mut as analogous methods when in fact they are called split and split_mut (which are covered immediately above on the same page).

Note from the Author or Editor:
On page 402, where we describe `slice.rsplit` and `rsplit_mut`, we say that these two methods are "Just like `slice` and `slice_mut`, but start at the end of the slice."

It should read "Just like `split` and `split_mut`, but start at the end of the slice."

D Patrick  Sep 17, 2021 
Page 431
Bottom table, last column

In the table 17-2, in the row of ch.is_ascii_digit(), there is a formatting issue in the 'Examples' cell on the right. The example "!'-'.is_ascii_digit()" is formatted as regular text, while it should be a fixed-width font.

Note from the Author or Editor:
In Table 17-2, one of the examples illustrating `is_ascii_digit` is shown in a variable-width font.

There is not in fact anything special about this example. All of the examples should be in the fixed-width font we use for code.

Kris van Rens  Jan 20, 2022 
PDF
Page 442
6th paragraph

Returnsan -> Returns an

Sungmann Cho  Jul 04, 2021  Nov 05, 2021
PDF
Page 492
last paragraph

wha tever -> whatever

Sungmann Cho  Jul 09, 2021  Nov 05, 2021
Page 550
Figure 20-2 and 2nd paragraph

`async_std::block_on` -> `async_std::task::block_on`

Note from the Author or Editor:
On page 548, in "Calling Async Functions from Synchronous Code: block_on", Figure 20-2 and the accompanying text refer to `async_std::block_on`.

The actual name of the function is `async_std::task::block_on`.

Sungmann Cho  Jan 31, 2024 
Printed
Page 606
Table 21-1

On page 606, in Table 21-1, the last three rows of the table are incorrect.

We listed `$( ... ),?` and `$( ... );?` as matching "0 or 1 times, separated by commas" or semicolons. Clearly that doesn't make sense. There is no such syntax in Rust. The last two rows of the table should be deleted.

The last remaining row, `$( ... )?`, should be labeled "Match 0 or 1 times" (deleting the words "with no separator").

Thanks to Sofiane Akermoun for reporting this issue.

Jason Orendorff
 
Apr 08, 2024 
Page 642
1st paragraph after bullet points

"the offset_from method gives the distance between two pointers in bytes"

The distance indicated by offset_from<T>(self, origin: *const T) is NOT in bytes, but in units of T.

Note from the Author or Editor:
On page 640, in "Raw Pointers", we wrote that "the `offset_from` method gives the distance between two pointers in bytes, though we're responsible for [...]".

This is wrong. The distance returned is the number of elements, not the number of bytes.

The text should read "the `offset_from` method gives the number of elements between two pointers, though we're responsible for [...]".

Tom  Jun 22, 2022 
PDF
Page 663
1st paragraph

missing opening double quote

Sungmann Cho  Jul 11, 2021  Nov 05, 2021