Skip to content
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

ch10 ジェネリック型、トレイト、ライフタイムの和訳を最新版に更新 #258

Open
wants to merge 11 commits into
base: master-ja
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
// ANCHOR_END: expect

// ANCHOR: print_guess
println!("You guessed: {}", guess); // 次のように予想しました: {}
println!("You guessed: {guess}"); // 次のように予想しました: {guess}
// ANCHOR_END: print_guess
}
// ANCHOR: all
40 changes: 16 additions & 24 deletions listings/ch02-guessing-game-tutorial/listing-02-02/Cargo.lock

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
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"
rand = "0.8.5"
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fn main() {
.read_line(&mut guess)
.expect("Failed to read line");

println!("You guessed: {}", guess);
println!("You guessed: {guess}");
}
16 changes: 4 additions & 12 deletions listings/ch02-guessing-game-tutorial/listing-02-03/Cargo.lock

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
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"
rand = "0.8.5"
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ fn main() {
println!("Guess the number!");

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

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

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

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

println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR: ch07-04
}
// ANCHOR_END: ch07-04
Expand Down
16 changes: 4 additions & 12 deletions listings/ch02-guessing-game-tutorial/listing-02-04/Cargo.lock

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
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"
rand = "0.8.5"
40 changes: 10 additions & 30 deletions listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,22 @@ $ cargo build
Compiling ppv-lite86 v0.2.10
Compiling rand_core v0.6.2
Compiling rand_chacha v0.3.0
Compiling rand v0.8.3
Compiling rand v0.8.5
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
error[E0308]: mismatched types (型が合いません)
--> src/main.rs:22:21
|
22 | match guess.cmp(&secret_number) {
| ^^^^^^^^^^^^^^ expected struct `String`, found integer
| (構造体`std::string::String`を予期したけど、整数型変数が見つかりました)
| --- ^^^^^^^^^^^^^^ expected `&String`, found `&{integer}`
| | (`&String`を予期したけど、`&{integer}`が見つかりました)
| |
| arguments to this method are incorrect
| (このメソッドへの引数が正しくありません)
|
= note: expected reference `&String`
found reference `&{integer}`
note: method defined here
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/cmp.rs:814:8

error[E0283]: type annotations needed for `{integer}`
--> src/main.rs:8:44
|
8 | let secret_number = rand::thread_rng().gen_range(1..101);
| ------------- ^^^^^^^^^ cannot infer type for type `{integer}`
| |
| consider giving `secret_number` a type
|
= note: multiple `impl`s satisfying `{integer}: SampleUniform` found in the `rand` crate:
- impl SampleUniform for i128;
- impl SampleUniform for i16;
- impl SampleUniform for i32;
- impl SampleUniform for i64;
and 8 more
note: required by a bound in `gen_range`
--> /Users/carolnichols/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.8.3/src/rng.rs:129:12
|
129 | T: SampleUniform,
| ^^^^^^^^^^^^^ required by this bound in `gen_range`
help: consider specifying the type arguments in the function call
|
8 | let secret_number = rand::thread_rng().gen_range::<T, R>(1..101);
| ++++++++

Some errors have detailed explanations: E0283, E0308.
For more information about an error, try `rustc --explain E0283`.
error: could not compile `guessing_game` due to 2 previous errors (先の2つのエラーのため、`guessing_game`をコンパイルできませんでした)
For more information about this error, try `rustc --explain E0308`.
error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error (先の1つのエラーのため、`guessing_game` (bin "guessing_game") をコンパイルできませんでした)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ fn main() {
// ANCHOR_END: here
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..101);
let secret_number = rand::thread_rng().gen_range(1..=100);

println!("The secret number is: {}", secret_number);
println!("The secret number is: {secret_number}");

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

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

println!("You guessed: {}", guess);
println!("You guessed: {guess}");

match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"), //小さすぎ!
Expand Down
16 changes: 4 additions & 12 deletions listings/ch02-guessing-game-tutorial/listing-02-05/Cargo.lock

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
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.3"
rand = "0.8.5"
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::io;
fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..101);
let secret_number = rand::thread_rng().gen_range(1..=100);

println!("The secret number is: {}", secret_number);
println!("The secret number is: {secret_number}");

loop {
println!("Please input your guess.");
Expand All @@ -28,7 +28,7 @@ fn main() {
};
// ANCHOR_END: ch19

println!("You guessed: {}", guess);
println!("You guessed: {guess}");

// --snip--
// ANCHOR_END: here
Expand Down
Loading