Skip to content

2024 Print Edition: updates to Word docs and more fixes to Markdown text #4272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion listings/ch08-common-collections/listing-08-19/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() {
// ANCHOR: here
let s1 = String::from("hello");
let s1 = String::from("hi");
let h = s1[0];
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder", "add_one"]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[workspace]
resolver = "2"
resolver = "3"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder", "add_one"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder", "add_one"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder", "add_one"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = [ "add_one","adder"]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
resolver = "3"
members = ["adder", "add_one"]
6 changes: 3 additions & 3 deletions listings/ch19-patterns-and-matching/listing-19-09/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn main() {
let some_option_value: Option<i32> = None;
// ANCHOR: here
if let Some(x) = some_option_value {
println!("{x}");
}
let Some(x) = some_option_value else {
return;
};
// ANCHOR_END: here
}
4 changes: 2 additions & 2 deletions listings/ch19-patterns-and-matching/listing-19-10/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
fn main() {
// ANCHOR: here
if let x = 5 {
println!("{x}");
let x = 5 else {
return;
};
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn main() {
println!("Text message: {text}");
}
Message::ChangeColor(r, g, b) => {
println!("Change the color to red {r}, green {g}, and blue {b}");
println!("Change color to red {r}, green {g}, and blue {b}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {

match numbers {
(first, _, third, _, fifth) => {
println!("Some numbers: {first}, {third}, {fifth}")
println!("Some numbers: {first}, {third}, {fifth}");
}
}
// ANCHOR_END: here
Expand Down
2 changes: 1 addition & 1 deletion listings/ch20-advanced-features/listing-20-11/output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ cargo +nightly miri run
Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
Running `/Users/chris/.rustup/toolchains/nightly-aarch64-apple-darwin/bin/cargo-miri runner target/miri/aarch64-apple-darwin/debug/unsafe-example`
Running `file:///home/.rustup/toolchains/nightly/bin/cargo-miri runner target/miri/debug/unsafe-example`
COUNTER: 3
2 changes: 2 additions & 0 deletions listings/ch20-advanced-features/listing-20-12/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// ANCHOR: here
unsafe trait Foo {
// methods go here
}

unsafe impl Foo for i32 {
// method implementations go here
}
// ANCHOR_END: here

fn main() {}
2 changes: 1 addition & 1 deletion listings/ch20-advanced-features/listing-20-29/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion listings/ch20-advanced-features/listing-20-29/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "macros-example"
name = "functions-example"
version = "0.1.0"
edition = "2024"

Expand Down
2 changes: 1 addition & 1 deletion listings/ch20-advanced-features/listing-20-31/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion listings/ch20-advanced-features/listing-20-31/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "hello_macro"
name = "functions-example"
version = "0.1.0"
edition = "2024"

Expand Down
15 changes: 8 additions & 7 deletions listings/ch20-advanced-features/listing-20-31/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use hello_macro::HelloMacro;
use hello_macro_derive::HelloMacro;

#[derive(HelloMacro)]
struct Pancakes;

fn main() {
Pancakes::hello_macro();
// ANCHOR: here
enum Status {
Value(u32),
Stop,
}

let list_of_statuses: Vec<Status> = (0u32..20).map(Status::Value).collect();
// ANCHOR_END: here
}
3 changes: 3 additions & 0 deletions listings/ch20-advanced-features/listing-20-32/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn returns_closure() -> impl Fn(i32) -> i32 {
|x| x + 1
}
20 changes: 20 additions & 0 deletions listings/ch20-advanced-features/listing-20-33/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$ cargo build
Compiling functions-example v0.1.0 (file:///projects/functions-example)
error[E0308]: mismatched types
--> src/main.rs:4:9
|
4 | returns_initialized_closure(123)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found a different opaque type
...
12 | fn returns_closure() -> impl Fn(i32) -> i32 {
| ------------------- the expected opaque type
...
16 | fn returns_initialized_closure(init: i32) -> impl Fn(i32) -> i32 {
| ------------------- the found opaque type
|
= note: expected opaque type `impl Fn(i32) -> i32` (opaque type at <src/main.rs:12:25>)
found opaque type `impl Fn(i32) -> i32` (opaque type at <src/main.rs:16:46>)
= note: distinct uses of `impl Trait` result in different opaque types

For more information about this error, try `rustc --explain E0308`.
error: could not compile `functions-example` (bin "functions-example") due to 1 previous error
15 changes: 15 additions & 0 deletions listings/ch20-advanced-features/listing-20-33/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
let handlers = vec![returns_closure(), returns_initialized_closure(123)];
for handler in handlers {
let output = handler(5);
println!("{output}");
}
}

fn returns_closure() -> impl Fn(i32) -> i32 {
|x| x + 1
}

fn returns_initialized_closure(init: i32) -> impl Fn(i32) -> i32 {
move |x| x + init
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ fn main() {
}
}

// ANCHOR: here
fn returns_closure() -> Box<dyn Fn(i32) -> i32> {
Box::new(|x| x + 1)
}

fn returns_initialized_closure(init: i32) -> Box<dyn Fn(i32) -> i32> {
Box::new(move |x| x + init)
}
// ANCHOR_END: here
6 changes: 6 additions & 0 deletions listings/ch20-advanced-features/listing-20-35/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions listings/ch20-advanced-features/listing-20-35/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "macros-example"
version = "0.1.0"
edition = "2024"

[dependencies]
9 changes: 9 additions & 0 deletions listings/ch20-advanced-features/listing-20-37/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use hello_macro::HelloMacro;
use hello_macro_derive::HelloMacro;

#[derive(HelloMacro)]
struct Pancakes;

fn main() {
Pancakes::hello_macro();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "hello_macro"
version = "0.1.0"
edition = "2024"

[dependencies]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "hello_macro"
version = "0.1.0"
edition = "2024"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub trait HelloMacro {
fn hello_macro();
}

This file was deleted.

Loading