Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
76fef1a
2nd chunk of chapters from copyedit
carols10cents Sep 28, 2025
e1794ee
Address copyedit queries in ch10
carols10cents Sep 29, 2025
8928cb3
Backport copyedit changes to ch10
carols10cents Sep 29, 2025
2c8cd56
Address copyedit queries in ch11
carols10cents Sep 30, 2025
08a83ae
Backport copyedit changes to ch11 md
carols10cents Sep 30, 2025
40ed7ff
Address copyedit queries in ch12
carols10cents Oct 1, 2025
6816b44
Backport copyedit changes to ch12
carols10cents Oct 1, 2025
2bd2979
Backport copyedit changes to ch13
carols10cents Oct 2, 2025
9ea48cc
Add ETAPS to the dictionary
carols10cents Oct 3, 2025
2e50899
Backport copyedit changes to ch14
carols10cents Oct 3, 2025
7b51a04
Address copyedit queries in ch15
carols10cents Oct 3, 2025
c08d07c
Backport copyedit changes to ch15
carols10cents Oct 3, 2025
825235a
Address copyedit queries in ch16
carols10cents Oct 4, 2025
861e91c
Backport copyedit changes to ch16
carols10cents Oct 4, 2025
d74b4c7
Address copyedit queries in ch18
carols10cents Oct 4, 2025
ce6f787
Add back index tags to ch18
carols10cents Oct 5, 2025
85ad183
Backport copyedit changes to ch18
carols10cents Oct 5, 2025
2cc56b1
Address copyedit queries in ch19
carols10cents Oct 7, 2025
ace3597
Backport copyedit changes to ch19
carols10cents Oct 7, 2025
cd61c43
Address copyedit queries in ch20
carols10cents Oct 7, 2025
06c56e4
Backport copyedit changes to ch20
carols10cents Oct 7, 2025
da610cd
Address copyedit queries in ch21
carols10cents Oct 13, 2025
239005b
Backport copyedit changes to ch21
carols10cents Oct 13, 2025
767e523
Add webpage to dictionary
carols10cents Oct 13, 2025
703c42e
Address copyedit queries in Appendix A
carols10cents Oct 13, 2025
e625ea3
Backport copyedit changes to Appendix A
carols10cents Oct 13, 2025
7156a8d
Backport copyedit changes to Appendix B
carols10cents Oct 13, 2025
8427f2d
Address copyedit queries in Appendix C
carols10cents Oct 14, 2025
6c5507d
Backport copyedit changes to Appendix C
carols10cents Oct 14, 2025
3cf9cac
Backport copyedit changes to Appendix D
carols10cents Oct 14, 2025
433c0b3
Backport copyedit changes to Appendix E
carols10cents Oct 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ eprintln
Erlang
ErrorKind
Español
ETAPS
eval
executables
ExitCode
Expand Down Expand Up @@ -624,6 +625,7 @@ wasi
wasn
weakt
WeatherForecast
webpage
WebSocket
whitespace
wildcard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ pub fn add(left: u64, right: u64) -> u64 {
left + right
}

// ANCHOR: here
#[cfg(test)]
mod tests {
use super::*;

// ANCHOR: here
#[test]
fn it_works() -> Result<(), String> {
let result = add(2, 2);
Expand All @@ -17,5 +17,5 @@ mod tests {
Err(String::from("two plus two does not equal four"))
}
}
// ANCHOR_END: here
}
// ANCHOR_END: here
2 changes: 1 addition & 1 deletion listings/ch15-smart-pointers/listing-15-14/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ $ cargo run
Compiling drop-example v0.1.0 (file:///projects/drop-example)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.60s
Running `target/debug/drop-example`
CustomSmartPointers created.
CustomSmartPointers created
Dropping CustomSmartPointer with data `other stuff`!
Dropping CustomSmartPointer with data `my stuff`!
2 changes: 1 addition & 1 deletion listings/ch15-smart-pointers/listing-15-14/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ fn main() {
let d = CustomSmartPointer {
data: String::from("other stuff"),
};
println!("CustomSmartPointers created.");
println!("CustomSmartPointers created");
}
4 changes: 2 additions & 2 deletions listings/ch15-smart-pointers/listing-15-15/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn main() {
let c = CustomSmartPointer {
data: String::from("some data"),
};
println!("CustomSmartPointer created.");
println!("CustomSmartPointer created");
c.drop();
println!("CustomSmartPointer dropped before the end of main.");
println!("CustomSmartPointer dropped before the end of main");
}
// ANCHOR_END: here
4 changes: 2 additions & 2 deletions listings/ch15-smart-pointers/listing-15-16/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ $ cargo run
Compiling drop-example v0.1.0 (file:///projects/drop-example)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.73s
Running `target/debug/drop-example`
CustomSmartPointer created.
CustomSmartPointer created
Dropping CustomSmartPointer with data `some data`!
CustomSmartPointer dropped before the end of main.
CustomSmartPointer dropped before the end of main
4 changes: 2 additions & 2 deletions listings/ch15-smart-pointers/listing-15-16/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn main() {
let c = CustomSmartPointer {
data: String::from("some data"),
};
println!("CustomSmartPointer created.");
println!("CustomSmartPointer created");
drop(c);
println!("CustomSmartPointer dropped before the end of main.");
println!("CustomSmartPointer dropped before the end of main");
}
// ANCHOR_END: here
2 changes: 2 additions & 0 deletions listings/ch15-smart-pointers/listing-15-25/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ANCHOR: here
use crate::List::{Cons, Nil};
use std::cell::RefCell;
use std::rc::Rc;
Expand All @@ -16,5 +17,6 @@ impl List {
}
}
}
// ANCHOR_END: here

fn main() {}
222 changes: 112 additions & 110 deletions nostarch/appendix.md

Large diffs are not rendered by default.

105 changes: 53 additions & 52 deletions nostarch/appendix_a.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,62 @@ directory, so all fixes need to be made in `/src/`.

The following lists contain keywords that are reserved for current or future
use by the Rust language. As such, they cannot be used as identifiers (except
as raw identifiers, as we’ll discuss in “Raw Identifiers” on page XX).
*Identifiers* are names of functions, variables, parameters, struct fields,
modules, crates, constants, macros, static values, attributes, types, traits,
or lifetimes.
as raw identifiers, as we discuss in the “Raw
Identifiers” section). *Identifiers* are names
of functions, variables, parameters, struct fields, modules, crates, constants,
macros, static values, attributes, types, traits, or lifetimes.

## Keywords Currently in Use
### Keywords Currently in Use

The following is a list of keywords currently in use, with their functionality
described.

* **`as` **: perform primitive casting, disambiguate the specific trait
containing an item, or rename items in `use` statements
* **`async` **: return a `Future` instead of blocking the current thread
* **`await` **: suspend execution until the result of a `Future` is ready
* **`break` **: exit a loop immediately
* **`const` **: define constant items or constant raw pointers
* **`continue` **: continue to the next loop iteration
* **`crate` **: in a module path, refers to the crate root
* **`dyn` **: dynamic dispatch to a trait object
* **`else` **: fallback for `if` and `if let` control flow constructs
* **`enum` **: define an enumeration
* **`extern` **: link an external function or variable
* **`false` **: Boolean false literal
* **`fn` **: define a function or the function pointer type
* **`for` **: loop over items from an iterator, implement a trait, or specify a
higher-ranked lifetime
* **`if` **: branch based on the result of a conditional expression
* **`impl` **: implement inherent or trait functionality
* **`in` **: part of `for` loop syntax
* **`let` **: bind a variable
* **`loop` **: loop unconditionally
* **`match` **: match a value to patterns
* **`mod` **: define a module
* **`move` **: make a closure take ownership of all its captures
* **`mut` **: denote mutability in references, raw pointers, or pattern bindings
* **`pub` **: denote public visibility in struct fields, `impl` blocks, or
modules
* **`ref` **: bind by reference
* **`return` **: return from function
* **`Self` **: a type alias for the type we are defining or implementing
* **`self` **: method subject or current module
* **`static` **: global variable or lifetime lasting the entire program
execution
* **`struct` **: define a structure
* **`super` **: parent module of the current module
* **`trait` **: define a trait
* **`true` **: Boolean true literal
* **`type` **: define a type alias or associated type
* **`union` **: define a union; is a keyword only when used in a union
declaration
* **`unsafe` **: denote unsafe code, functions, traits, or implementations
* **`use` **: bring symbols into scope
* **`where` **: denote clauses that constrain a type
* **`while` **: loop conditionally based on the result of an expression

## Keywords Reserved for Future Use
* **`as`**: Perform primitive casting, disambiguate the specific trait
containing an item, or rename items in `use` statements.
* **`async`**: Return a `Future` instead of blocking the current thread.
* **`await`**: Suspend execution until the result of a `Future` is ready.
* **`break`**: Exit a loop immediately.
* **`const`**: Define constant items or constant raw pointers.
* **`continue`**: Continue to the next loop iteration.
* **`crate`**: In a module path, refers to the crate root.
* **`dyn`**: Dynamic dispatch to a trait object.
* **`else`**: Fallback for `if` and `if let` control flow constructs.
* **`enum`**: Define an enumeration.
* **`extern`**: Link an external function or variable.
* **`false`**: Boolean false literal.
* **`fn`**: Define a function or the function pointer type.
* **`for`**: Loop over items from an iterator, implement a trait, or specify a
higher ranked lifetime.
* **`if`**: Branch based on the result of a conditional expression.
* **`impl`**: Implement inherent or trait functionality.
* **`in`**: Part of `for` loop syntax.
* **`let`**: Bind a variable.
* **`loop`**: Loop unconditionally.
* **`match`**: Match a value to patterns.
* **`mod`**: Define a module.
* **`move`**: Make a closure take ownership of all its captures.
* **`mut`**: Denote mutability in references, raw pointers, or pattern bindings.
* **`pub`**: Denote public visibility in struct fields, `impl` blocks, or
modules.
* **`ref`**: Bind by reference.
* **`return`**: Return from function.
* **`Self`**: A type alias for the type we are defining or implementing.
* **`self`**: Method subject or current module.
* **`static`**: Global variable or lifetime lasting the entire program
execution.
* **`struct`**: Define a structure.
* **`super`**: Parent module of the current module.
* **`trait`**: Define a trait.
* **`true`**: Boolean true literal.
* **`type`**: Define a type alias or associated type.
* **`union`**: Define a union; is a keyword only when
used in a union declaration.
* **`unsafe`**: Denote unsafe code, functions, traits, or implementations.
* **`use`**: Bring symbols into scope.
* **`where`**: Denote clauses that constrain a type.
* **`while`**: Loop conditionally based on the result of an expression.

### Keywords Reserved for Future Use

The following keywords do not yet have any functionality but are reserved by
Rust for potential future use:
Expand All @@ -75,6 +75,7 @@ Rust for potential future use:
* `box`
* `do`
* `final`
* `gen`
* `macro`
* `override`
* `priv`
Expand All @@ -84,7 +85,7 @@ Rust for potential future use:
* `virtual`
* `yield`

## Raw Identifiers
### Raw Identifiers

*Raw identifiers* are the syntax that lets you use keywords where they wouldn’t
normally be allowed. You use a raw identifier by prefixing a keyword with `r#`.
Expand Down
14 changes: 7 additions & 7 deletions nostarch/appendix_b.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type | |
| `->` | `fn(...) -> type`, `|...| -> type` | Function and closure return type | |
| `.` | `expr.ident` | Field access | |
| `.` | `expr.ident(expr, ...)` | Method call | |
| `.` | `expr.0`, `expr.1`, etc. | Tuple indexing | |
| `.` | `expr.0`, `expr.1`, and so on | Tuple indexing | |
| `..` | `..`, `expr..`, `..expr`, `expr..expr` | Right-exclusive range literal
| `PartialOrd` |
| `..=` | `..=expr`, `expr..=expr` | Right-inclusive range literal |
Expand All @@ -61,7 +61,7 @@ binding | |
inclusive range pattern | |
| `/` | `expr / expr` | Arithmetic division | `Div` |
| `/=` | `var /= expr` | Arithmetic division and assignment | `DivAssign` |
| `: | `pat: type`, `ident: type` | Constraints | |
| `:` | `pat: type`, `ident: type` | Constraints | |
| `:` | `ident: expr` | Struct field initializer | |
| `:` | `'a: loop {...}` | Loop label | |
| `;` | `expr;` | Statement and item terminator | |
Expand Down Expand Up @@ -94,12 +94,12 @@ is, they don’t behave like a function or method call.
Table B-2 shows symbols that appear on their own and are valid in a variety of
locations.

Table B-2: Stand-Alone Syntax
Table B-2: Stand-alone Syntax

| Symbol | Explanation |
|---|---|
| `'ident` | Named lifetime or loop label |
| Digits immediately followed by `u8`, `i32`, `f64`, `usize`, and so on |
| Digits immediately followed by `u8`, `i32`, `f64`, `usize`, and so on |
Numeric literal of specific type |
| `"..."` | String literal |
| `r"..."`, `r#"..."#`, `r##"..."##`, and so on | Raw string literal; escape
Expand Down Expand Up @@ -147,14 +147,14 @@ Table B-4: Generics
|---|---|
| `path<...>` | Specifies parameters to a generic type in a type (for example,
`Vec<u8>`) |
| `path::<...>, method::<...>` | Specifies parameters to a generic type,
function, or method in an expression; often referred to as turbofish (for
| `path::<...>`, `method::<...>` | Specifies parameters to a generic type,
function, or method in an expression; often referred to as *turbofish* (for
example, `"42".parse::<i32>()`) |
| `fn ident<...> ...` | Define generic function |
| `struct ident<...> ...` | Define generic structure |
| `enum ident<...> ...` | Define generic enumeration |
| `impl<...> ...` | Define generic implementation |
| `for<...> type` | Higher-ranked lifetime bounds |
| `for<...> type` | Higher ranked lifetime bounds |
| `type<ident=type>` | A generic type where one or more associated types have
specific assignments (for example, `Iterator<Item=T>`) |

Expand Down
33 changes: 17 additions & 16 deletions nostarch/appendix_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ would be most relevant to them? The Rust compiler doesn’t have this insight, s
it can’t provide appropriate default behavior for you.

The list of derivable traits provided in this appendix is not comprehensive:
libraries can implement `derive` for their own traits, making the list of
Libraries can implement `derive` for their own traits, making the list of
traits you can use `derive` with truly open ended. Implementing `derive`
involves using a procedural macro, which is covered in “Macros” on page XX.
involves using a procedural macro, which is covered in the “Custom `derive`
Macros” section in Chapter 20.

## Debug for Programmer Output

Expand All @@ -54,8 +55,8 @@ at a particular point in a program’s execution.

The `Debug` trait is required, for example, in the use of the `assert_eq!`
macro. This macro prints the values of instances given as arguments if the
equality assertion fails so programmers can see why the two instances weren’t
equal.
equality assertion fails so that programmers can see why the two instances
weren’t equal.

## PartialEq and Eq for Equality Comparisons

Expand All @@ -64,7 +65,7 @@ equality and enables use of the `==` and `!=` operators.

Deriving `PartialEq` implements the `eq` method. When `PartialEq` is derived on
structs, two instances are equal only if *all* fields are equal, and the
instances are not equal if any fields are not equal. When derived on enums,
instances are not equal if *any* fields are not equal. When derived on enums,
each variant is equal to itself and not equal to the other variants.

The `PartialEq` trait is required, for example, with the use of the
Expand All @@ -75,7 +76,7 @@ The `Eq` trait has no methods. Its purpose is to signal that for every value of
the annotated type, the value is equal to itself. The `Eq` trait can only be
applied to types that also implement `PartialEq`, although not all types that
implement `PartialEq` can implement `Eq`. One example of this is floating-point
number types: the implementation of floating-point numbers states that two
number types: The implementation of floating-point numbers states that two
instances of the not-a-number (`NaN`) value are not equal to each other.

An example of when `Eq` is required is for keys in a `HashMap<K, V>` so that
Expand All @@ -91,8 +92,8 @@ that also implement `PartialEq`.
Deriving `PartialOrd` implements the `partial_cmp` method, which returns an
`Option<Ordering>` that will be `None` when the values given don’t produce an
ordering. An example of a value that doesn’t produce an ordering, even though
most values of that type can be compared, is the not-a-number (`NaN`) floating
point value. Calling `partial_cmp` with any floating-point number and the `NaN`
most values of that type can be compared, is the `NaN` floating point value.
Calling `partial_cmp` with any floating-point number and the `NaN`
floating-point value will return `None`.

When derived on structs, `PartialOrd` compares two instances by comparing the
Expand All @@ -119,8 +120,8 @@ a data structure that stores data based on the sort order of the values.

The `Clone` trait allows you to explicitly create a deep copy of a value, and
the duplication process might involve running arbitrary code and copying heap
data. See “Variables and Data Interacting with Clone” on page XX for more
information on `Clone`.
data. See the “Variables and Data Interacting with Clone” section in Chapter 4
for more information on `Clone`.

Deriving `Clone` implements the `clone` method, which when implemented for the
whole type, calls `clone` on each of the parts of the type. This means all the
Expand All @@ -129,11 +130,11 @@ fields or values in the type must also implement `Clone` to derive `Clone`.
An example of when `Clone` is required is when calling the `to_vec` method on a
slice. The slice doesn’t own the type instances it contains, but the vector
returned from `to_vec` will need to own its instances, so `to_vec` calls
`clone` on each item. Thus the type stored in the slice must implement `Clone`.
`clone` on each item. Thus, the type stored in the slice must implement `Clone`.

The `Copy` trait allows you to duplicate a value by only copying bits stored on
the stack; no arbitrary code is necessary. See “Stack-Only Data: Copy” on page
XX for more information on `Copy`.
the stack; no arbitrary code is necessary. See the “Stack-Only Data: Copy”
section in Chapter 4 for more information on `Copy`.

The `Copy` trait doesn’t define any methods to prevent programmers from
overloading those methods and violating the assumption that no arbitrary code
Expand Down Expand Up @@ -172,9 +173,9 @@ meaning all fields or values in the type must also implement `Default` to
derive `Default`.

The `Default::default` function is commonly used in combination with the struct
update syntax discussed in “Creating Instances from Other Instances with Struct
Update Syntax” on page XX. You can customize a few fields of a struct and then
set and use a default value for the rest of the fields by using
update syntax discussed in the “Creating Instances with Struct Update Syntax”
section in Chapter 5. You can customize a few fields of a struct and then set
and use a default value for the rest of the fields by using
`..Default::default()`.

The `Default` trait is required when you use the method `unwrap_or_default` on
Expand Down
10 changes: 5 additions & 5 deletions nostarch/appendix_d.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ warning fixes, a linter, and integrating with IDEs.

The `rustfmt` tool reformats your code according to the community code style.
Many collaborative projects use `rustfmt` to prevent arguments about which
style to use when writing Rust: everyone formats their code using the tool.
style to use when writing Rust: Everyone formats their code using the tool.

Rust installations include `rustfmt` by default, so you should already have the
programs `rustfmt` and `cargo-fmt` on your system. These two commands are
analogous to `rustc` and `cargo` in that `rustfmt` allows finer-grained control
analogous to `rustc` and `cargo` in that `rustfmt` allows finer grained control
and `cargo-fmt` understands conventions of a project that uses Cargo. To format
any Cargo project, enter the following:

Expand Down Expand Up @@ -95,9 +95,9 @@ different Rust editions. Editions are covered in Appendix E.

## More Lints with Clippy

The Clippy tool is a collection of lints to analyze your code so you can catch
common mistakes and improve your Rust code. Clippy is included with standard
Rust installations.
The Clippy tool is a collection of lints to analyze your code so that you can
catch common mistakes and improve your Rust code. Clippy is included with
standard Rust installations.

To run Clippy’s lints on any Cargo project, enter the following:

Expand Down
Loading