TS McNamara (34) [Avatar] Offline
Chapter 3 - Compound Data Structures - is live. It is the end result of a significant rewrites and refactors, so do let me know if there are any issues with flow. The chapter covers a great deal, but I really hope that it's a worthwhile read.
55925 (25) [Avatar] Offline
Listing 3.1
"The compiler won't distinguish between String & File" - better use the word 'and' instead of ampersand, as in Rust context ampersand is used as a symbol, and "String & File" may look like a union type syntax for people coming from different languages, skimming through here.
55925 (25) [Avatar] Offline
3.2 Modeling files with structs
Listing 3.2

Note (4): "We'll use the vec! macro..." AFAIC there is no vec macro in use with "data: Vec::new()"

Note (5): "Accessing field by reference prevents use after move issues" - is not very comprehensible by now.

Box: "The newtype pattern" mentions a tuple again, but we do not know much about tuple until now.

In Listing 3.3 we surprisingly see a struct with parentheses instead of curly braces. This was surprising, and I had to google for it. Would be nice to at least mention the word "tuple struct" so the reader knows that this is not a typo, but again a new concept.

Listing 3.5
Note (7) seems to belong to note (6), as I don't think "save_to.append" allocates the buffer ?

Note (9) end of sentence is missing, so what is the replacement?

Note (10) please use the written word 'and' and not '&' here.

55925 (25) [Avatar] Offline
3.3 Adding methods to a struct with impl
Table 3.1
The table is a bit confusing. While the left column is clear, the right column is insofar irritating, that
a) the following listing 3.6 declares the new Method with only one parameter, and indeed the implementation of the upper left cell, so the upper right cell seems to have an obsolete argument.

b) The lower right call first seems clear, but should refer to the new_with_data method later presented to us in Listing 3.7, to be consistent.

After Listing 3.6, at the top of page 56 is a section enclosed in \\\\\ which seems out of place, or referring to an older version of the listing?

55925 (25) [Avatar] Offline
3.4.1 / 3.4.2 presenting the listing before talking about it
In 3.4.1 Listing 3.8 is referred at page 59, but only presented at page 61, after some text and a flow diagram. It would be nice to first see the code and then get into the discussion about it.

Listing 3.8 Note (5) : "Return true 1 in every n times" - the 1 after true is confusing, should be "Return true once in every n times" to be more clear.

In 3.4.2 again the reader's flow is interrupted, as he has to jump from page 62 to page 63, study the listing, get back to the discussion about it on page 62 which would otherwise not be comprehensible, and then end the section with skipping the now known listing to read the rest on page 64.

55925 (25) [Avatar] Offline
3.5 enums, Listing 3.11 doesn't show use of match
On page 66 the first bullet point states "They work together with Rust's pattern matching capabilities to help you build robust, readable code. This is visible on lines 19-23 of Listing 3.11"

Unfortunately that is not the case. The mentioned lines only show matching parts[0], which is a string, against string literals.

On the other hand, seeing match on events in action would be a valuable topic here.
40379 (1) [Avatar] Offline
Hi there.

In the example 3.1 it seems the compiler doesn't like if you put
in that line of the code. I got:
error: an inner attribute is not permitted in this context
--> r0061.rs:12:3
12 | #![allow(dead_code)]
inner attributes and doc comments, like `#![no_std]` or `//! My crate`, annotate the item enclosing them, and are usually found at the beginning of source files.

so i had to move that code in the second line, just after
and all worked fine.

I'm using rel 1.20.

KOZAKI (6) [Avatar] Offline
There is an explanation that "an explicit type needs to be provided" in the note ? of List 3.7.

However, it worked fine without providing the type of f3_data as a trial.
KOZAKI (6) [Avatar] Offline
Is the line #2 of Listing 3.8 a mistake of use rand::Rng ?