Skip to content

Commit cc34c09

Browse files
committed
ch02 数当てゲームのプログラミングの和訳を最新版に更新
rust-lang/book@19c40bf
1 parent 7573273 commit cc34c09

File tree

31 files changed

+402
-424
lines changed

31 files changed

+402
-424
lines changed

listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
// ANCHOR_END: expect
2626

2727
// ANCHOR: print_guess
28-
println!("You guessed: {}", guess); // 次のように予想しました: {}
28+
println!("You guessed: {guess}"); // 次のように予想しました: {guess}
2929
// ANCHOR_END: print_guess
3030
}
3131
// ANCHOR: all

listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock

+16-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rand = "0.8.3"
9+
rand = "0.8.5"

listings/ch02-guessing-game-tutorial/listing-02-02/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ fn main() {
1111
.read_line(&mut guess)
1212
.expect("Failed to read line");
1313

14-
println!("You guessed: {}", guess);
14+
println!("You guessed: {guess}");
1515
}

listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock

+4-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rand = "0.8.3"
9+
rand = "0.8.5"

listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ fn main() {
88
println!("Guess the number!");
99

1010
// ANCHOR: ch07-04
11-
let secret_number = rand::thread_rng().gen_range(1..101);
11+
let secret_number = rand::thread_rng().gen_range(1..=100);
1212
// ANCHOR_END: ch07-04
1313

14-
println!("The secret number is: {}", secret_number); //秘密の数字は次の通り: {}
14+
println!("The secret number is: {secret_number}"); //秘密の数字は次の通り: {secret_number}
1515

1616
println!("Please input your guess.");
1717

@@ -21,7 +21,7 @@ fn main() {
2121
.read_line(&mut guess)
2222
.expect("Failed to read line");
2323

24-
println!("You guessed: {}", guess);
24+
println!("You guessed: {guess}");
2525
// ANCHOR: ch07-04
2626
}
2727
// ANCHOR_END: ch07-04

listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock

+4-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rand = "0.8.3"
9+
rand = "0.8.5"

listings/ch02-guessing-game-tutorial/listing-02-04/output.txt

+10-30
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,22 @@ $ cargo build
55
Compiling ppv-lite86 v0.2.10
66
Compiling rand_core v0.6.2
77
Compiling rand_chacha v0.3.0
8-
Compiling rand v0.8.3
8+
Compiling rand v0.8.5
99
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
1010
error[E0308]: mismatched types (型が合いません)
1111
--> src/main.rs:22:21
1212
|
1313
22 | match guess.cmp(&secret_number) {
14-
| ^^^^^^^^^^^^^^ expected struct `String`, found integer
15-
| (構造体`std::string::String`を予期したけど、整数型変数が見つかりました)
14+
| --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}`
15+
| | (`&String`を予期したけど、`&{integer}`が見つかりました)
16+
| |
17+
| arguments to this method are incorrect
18+
| (このメソッドへの引数が正しくありません)
1619
|
1720
= note: expected reference `&String`
1821
found reference `&{integer}`
22+
note: method defined here
23+
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/cmp.rs:814:8
1924

20-
error[E0283]: type annotations needed for `{integer}`
21-
--> src/main.rs:8:44
22-
|
23-
8 | let secret_number = rand::thread_rng().gen_range(1..101);
24-
| ------------- ^^^^^^^^^ cannot infer type for type `{integer}`
25-
| |
26-
| consider giving `secret_number` a type
27-
|
28-
= note: multiple `impl`s satisfying `{integer}: SampleUniform` found in the `rand` crate:
29-
- impl SampleUniform for i128;
30-
- impl SampleUniform for i16;
31-
- impl SampleUniform for i32;
32-
- impl SampleUniform for i64;
33-
and 8 more
34-
note: required by a bound in `gen_range`
35-
--> /Users/carolnichols/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.3/src/rng.rs:129:12
36-
|
37-
129 | T: SampleUniform,
38-
| ^^^^^^^^^^^^^ required by this bound in `gen_range`
39-
help: consider specifying the type arguments in the function call
40-
|
41-
8 | let secret_number = rand::thread_rng().gen_range::<T, R>(1..101);
42-
| ++++++++
43-
44-
Some errors have detailed explanations: E0283, E0308.
45-
For more information about an error, try `rustc --explain E0283`.
46-
error: could not compile `guessing_game` due to 2 previous errors (先の2つのエラーのため、`guessing_game`をコンパイルできませんでした)
25+
For more information about this error, try `rustc --explain E0308`.
26+
error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error (先の1つのエラーのため、`guessing_game` (bin "guessing_game") をコンパイルできませんでした)

listings/ch02-guessing-game-tutorial/listing-02-04/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ fn main() {
88
// ANCHOR_END: here
99
println!("Guess the number!");
1010

11-
let secret_number = rand::thread_rng().gen_range(1..101);
11+
let secret_number = rand::thread_rng().gen_range(1..=100);
1212

13-
println!("The secret number is: {}", secret_number);
13+
println!("The secret number is: {secret_number}");
1414

1515
println!("Please input your guess.");
1616

@@ -21,7 +21,7 @@ fn main() {
2121
.expect("Failed to read line");
2222
// ANCHOR: here
2323

24-
println!("You guessed: {}", guess);
24+
println!("You guessed: {guess}");
2525

2626
match guess.cmp(&secret_number) {
2727
Ordering::Less => println!("Too small!"), //小さすぎ!

listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock

+4-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rand = "0.8.3"
9+
rand = "0.8.5"

listings/ch02-guessing-game-tutorial/listing-02-05/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::io;
55
fn main() {
66
println!("Guess the number!");
77

8-
let secret_number = rand::thread_rng().gen_range(1..101);
8+
let secret_number = rand::thread_rng().gen_range(1..=100);
99

10-
println!("The secret number is: {}", secret_number);
10+
println!("The secret number is: {secret_number}");
1111

1212
loop {
1313
println!("Please input your guess.");
@@ -28,7 +28,7 @@ fn main() {
2828
};
2929
// ANCHOR_END: ch19
3030

31-
println!("You guessed: {}", guess);
31+
println!("You guessed: {guess}");
3232

3333
// --snip--
3434
// ANCHOR_END: here

0 commit comments

Comments
 (0)