Skip to content

Commit a462e87

Browse files
committed
update original
1 parent cfaccb5 commit a462e87

14 files changed

Lines changed: 444 additions & 422 deletions

File tree

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
fn main() {
2-
let favorite_color: Option<&str> = None;
3-
let is_tuesday = false;
4-
let age: Result<u8, _> = "34".parse();
5-
6-
if let Some(color) = favorite_color {
7-
println!("Using your favorite color, {color}, as the background");
8-
} else if is_tuesday {
9-
println!("Tuesday is green day!");
10-
} else if let Ok(age) = age {
11-
if age > 30 {
12-
println!("Using purple as the background color");
13-
} else {
14-
println!("Using orange as the background color");
15-
}
16-
} else {
17-
println!("Using blue as the background color");
18-
}
2+
// ANCHOR: here
3+
let (x, y, z) = (1, 2, 3);
4+
// ANCHOR_END: here
195
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$ cargo run
2+
Compiling patterns v0.1.0 (file:///projects/patterns)
3+
error[E0308]: mismatched types
4+
--> src/main.rs:2:9
5+
|
6+
2 | let (x, y) = (1, 2, 3);
7+
| ^^^^^^ --------- this expression has type `({integer}, {integer}, {integer})`
8+
| |
9+
| expected a tuple with 3 elements, found one with 2 elements
10+
|
11+
= note: expected tuple `({integer}, {integer}, {integer})`
12+
found tuple `(_, _)`
13+
14+
For more information about this error, try `rustc --explain E0308`.
15+
error: could not compile `patterns` (bin "patterns") due to 1 previous error
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
fn main() {
22
// ANCHOR: here
3-
let (tx, rx) = std::sync::mpsc::channel();
4-
std::thread::spawn(move || {
5-
for val in [1, 2, 3] {
6-
tx.send(val).unwrap();
7-
}
8-
});
9-
10-
while let Ok(value) = rx.recv() {
11-
println!("{value}");
12-
}
3+
let (x, y) = (1, 2, 3);
134
// ANCHOR_END: here
145
}

rustbook-en/listings/ch19-patterns-and-matching/listing-19-03/output.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
fn main() {
2-
// ANCHOR: here
3-
let v = vec!['a', 'b', 'c'];
2+
let favorite_color: Option<&str> = None;
3+
let is_tuesday = false;
4+
let age: Result<u8, _> = "34".parse();
45

5-
for (index, value) in v.iter().enumerate() {
6-
println!("{value} is at index {index}");
6+
if let Some(color) = favorite_color {
7+
println!("Using your favorite color, {color}, as the background");
8+
} else if is_tuesday {
9+
println!("Tuesday is green day!");
10+
} else if let Ok(age) = age {
11+
if age > 30 {
12+
println!("Using purple as the background color");
13+
} else {
14+
println!("Using orange as the background color");
15+
}
16+
} else {
17+
println!("Using blue as the background color");
718
}
8-
// ANCHOR_END: here
919
}
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
fn main() {
22
// ANCHOR: here
3-
let (x, y, z) = (1, 2, 3);
3+
let (tx, rx) = std::sync::mpsc::channel();
4+
std::thread::spawn(move || {
5+
for val in [1, 2, 3] {
6+
tx.send(val).unwrap();
7+
}
8+
});
9+
10+
while let Ok(value) = rx.recv() {
11+
println!("{value}");
12+
}
413
// ANCHOR_END: here
514
}
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
$ cargo run
22
Compiling patterns v0.1.0 (file:///projects/patterns)
3-
error[E0308]: mismatched types
4-
--> src/main.rs:2:9
5-
|
6-
2 | let (x, y) = (1, 2, 3);
7-
| ^^^^^^ --------- this expression has type `({integer}, {integer}, {integer})`
8-
| |
9-
| expected a tuple with 3 elements, found one with 2 elements
10-
|
11-
= note: expected tuple `({integer}, {integer}, {integer})`
12-
found tuple `(_, _)`
13-
14-
For more information about this error, try `rustc --explain E0308`.
15-
error: could not compile `patterns` (bin "patterns") due to 1 previous error
3+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.52s
4+
Running `target/debug/patterns`
5+
a is at index 0
6+
b is at index 1
7+
c is at index 2
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
fn main() {
22
// ANCHOR: here
3-
let (x, y) = (1, 2, 3);
3+
let v = vec!['a', 'b', 'c'];
4+
5+
for (index, value) in v.iter().enumerate() {
6+
println!("{value} is at index {index}");
7+
}
48
// ANCHOR_END: here
59
}

rustbook-en/listings/ch19-patterns-and-matching/listing-19-29/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ fn main() {
88

99
match msg {
1010
Message::Hello {
11-
id: id_variable @ 3..=7,
12-
} => println!("Found an id in range: {id_variable}"),
11+
id: id @ 3..=7,
12+
} => println!("Found an id in range: {id}"),
1313
Message::Hello { id: 10..=12 } => {
1414
println!("Found an id in another range")
1515
}

0 commit comments

Comments
 (0)