Errata

Effective Rust

Errata for Effective 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
Page p.61
paragraph starts with 'The String::from_utf8_unchecked and String::from_utf8 entrypoints'

The paragraph says both of the 'from_utf8_unchecked' and 'from_utf8' are 'fallaible', but I believe 'from_utf8_unchecked' is not fallible.

Note from the Author or Editor:
(p.163 of printed book)
The example is demonstrating both infallible+fallible variants, so the text:

"The String::from_utf8_unchecked and String::from_utf8 entrypoints in the standard library are an example of the latter ..."

should read:

"The String::from_utf8_unchecked and String::from_utf8 entrypoints in the standard library are an example of such a pair ..."

HIDEMOTO NAKADA  Aug 16, 2024 
Page p.21
3rd paragraph, starts with 'In some situation ..'

in the sentence,
"because Rust requires that the code deal with both variants of the Error enum"

`Error` should be `Result`.

HIDEMOTO NAKADA  Aug 16, 2024 
Page p.163
last sentence.

"actually a different function (tname::<u32> or tname::<Square>):"

"tname::<Square>" should be "tname::<Vec<i32>>", for this example.

Note from the Author or Editor:
(p.165 of printed book, last paragraph)

HIDEMOTO NAKADA  Aug 16, 2024 
Page p.100
Figure 2-2

on the right of the figure.
"Any for Square vtable"
should be
"Shape for Square vtable"

Note from the Author or Editor:
(Note for O'Reilly: a diagram correction I pointed out for QC2 was incorrectly applied here.)

HIDEMOTO NAKADA  Sep 17, 2024 
Printed
Page p.60
Paragraphs 4-7, after the code sample

(Reported by HIDEMOTO NAKADA)

The paragraphs describing `Borrow` and `ToOwned` are somewhat confused and unhelpful. A better version would be:

The standard library's container types have more realistic uses of `Borrow`. For example, `HashMap::get`uses `Borrow` to allow convenient retrieval of entries by reference to the either the key's actual type `K`, or to some other type that it can be borrowed as. For example, a `HashMap` keyed by `String` can `get` entries via either `&String` or `&str`.

The `ToOwned`trait builds on the `Borrow` trait, adding a `to_owned()` method that produces a new owned item from the borrowed type. This is a generalization of the `Clone` trait: where `Clone` specifically requires a reference `&T` of the same type to produce a new `T`, `ToOwned` instead produces a new `T` from some other type—specifically, the type that's the result of the `borrow()`.

A more concrete example makes this clearer. The standard library allows a `&String` to be converted into a `&str`, via an implementation of `Borrow<str>` for `String`. A new `String` instance can be `clone`d from a `&String` reference, but to get a new `String` from a `&str` reference, the `ToOwned` implementation that the standard library provides (for `str`) is needed.

Although it's not (just) a pointer type, the `Cow` type is worth mentioning at this point, because it uses `ToOwned` to cope with a combination of borrowed and owned data. `Cow` is an `enum` that can hold either owned data or a reference to borrowed data. The peculiar name stands for "clone-on-write": a `Cow` input can remain as borrowed data right up to the point where it needs to be modified, but it becomes an owned copy (using `ToOwned`) at the point where the data needs to be altered.

David Drysdale
 
Sep 28, 2024 
Page 46
Below the error message of the not compiling code example

The text says "The code can't implement Default for chrono::Utc because...", but in the code example time::Date is used, also the error message says "the trait `Default` is not implemented for `Date`". Looks for me like in a previous version chrono::Utc was used and now time::Data, but the text was forgotten to adapt?

Note from the Author or Editor:
Yes, the text needs an update to replace `chrono::Utc` with `time::Date` to match the code.

Daniel Szymanski  Jul 31, 2024 
Printed
Page 125, Item 15
3rd bullet

(Spotted by Alan Stokes)

"- Like a C/C++ pointer or reference, a Rust reference can be modified after creation to refer to something different."

should read:

"- Like a C/C++ pointer, a Rust reference can be modified after creation to refer to something different."

(because C++ references can't be rebound)

David Drysdale
 
Jun 28, 2024 
Printed
Page 145, Item 16
Second set of bullets, bullet 2

(Spotted by Alan Stokes)

Cow does not actually need unsafe internally; its functionality is provided using safe code. So a different example would be better here, e.g. replace the whole bullet with:

"- The `std::sync::atomic` module provides atomic versions of primitive types."

David Drysdale
 
Jun 28, 2024