Skip to content

Commit bf95e61

Browse files
authored
Merge pull request #138 from ixkaito/ch02-00-remove-extern-crate
Remove the `extern crate` line and update the translation
2 parents 7e2cdb9 + dc86b59 commit bf95e61

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/ch02-00-guessing-game-tutorial.md

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,6 @@ Now that you've added the `rand` crate to *Cargo.toml*, let's start using
973973
<span class="filename">ファイル名: src/main.rs</span>
974974

975975
```rust,ignore
976-
extern crate rand;
977-
978976
use std::io;
979977
use rand::Rng;
980978
@@ -989,7 +987,8 @@ fn main() {
989987
990988
let mut guess = String::new();
991989
992-
io::stdin().read_line(&mut guess)
990+
io::stdin()
991+
.read_line(&mut guess)
993992
.expect("Failed to read line");
994993
995994
println!("You guessed: {}", guess);
@@ -1004,38 +1003,29 @@ random number</span>
10041003
<span class="caption">リスト2-3: 乱数を生成するコードの追加</span>
10051004

10061005
<!--
1007-
First, we add a line that lets Rust know we’ll be using the `rand` crate as an
1008-
external dependency. This also does the equivalent of calling `use rand`, so
1009-
now we can call anything in the `rand` crate by placing `rand::` before it.
1010-
-->
1011-
1012-
まず、コンパイラに`rand`クレートを外部依存として使用することを知らせる行を追加しています。
1013-
これにより、`use rand`を呼ぶのと同じ効果が得られるので、`rand`クレートのものを`rand::`という接頭辞をつけて呼び出せるようになりました。
1014-
1015-
<!--
1016-
Next, we add another `use` line: `use rand::Rng`. The `Rng` trait defines
1006+
First, we add a `use` line: `use rand::Rng`. The `Rng` trait defines
10171007
methods that random number generators implement, and this trait must be in
10181008
scope for us to use those methods. Chapter 10 will cover traits in detail.
10191009
-->
10201010

1021-
次に、別の`use`行を追加しています: `use rand::Rng`ですね。`Rng`トレイトは乱数生成器が実装するメソッドを定義していて、
1011+
まず、`use`行を追加しています: `use rand::Rng`ですね。`Rng`トレイトは乱数生成器が実装するメソッドを定義していて、
10221012
このトレイトがスコープにないと、メソッドを使用できないのです。トレイトについて詳しくは、
10231013
第10章で解説します。
10241014

10251015
<!--
1026-
Also, we’re adding two more lines in the middle. The `rand::thread_rng` function
1016+
Next, we’re adding two lines in the middle. The `rand::thread_rng` function
10271017
will give us the particular random number generator that we’re going to use:
10281018
one that is local to the current thread of execution and seeded by the
1029-
operating system. Next, we call the `gen_range` method on the random number
1019+
operating system. Then we call the `gen_range` method on the random number
10301020
generator. This method is defined by the `Rng` trait that we brought into
10311021
scope with the `use rand::Rng` statement. The `gen_range` method takes two
10321022
numbers as arguments and generates a random number between them. It’s inclusive
10331023
on the lower bound but exclusive on the upper bound, so we need to specify `1`
10341024
and `101` to request a number between 1 and 100.
10351025
-->
10361026

1037-
また、途中に2行追加もしています`rand::thread_rng`関数は、これから使う特定の乱数生成器を返してくれます: この乱数生成器は、実行スレッドに固有で、OSにより、シード値を与えられています。
1038-
次に、この乱数生成器の`gen_range`メソッドを呼び出しています。このメソッドは、
1027+
次に、途中に2行を追加しています`rand::thread_rng`関数は、これから使う特定の乱数生成器を返してくれます: この乱数生成器は、実行スレッドに固有で、OSにより、シード値を与えられています。
1028+
そして、この乱数生成器の`gen_range`メソッドを呼び出しています。このメソッドは、
10391029
`use rand::Rng`文でスコープに導入した`Rng`トレイトで定義されています。`gen_range`メソッドは二つの数字を引数に取り、
10401030
それらの間の乱数を生成してくれます。範囲は下限値を含み、上限値を含まないため、`1``101`と指定しないと1から100の範囲の数字は得られません。
10411031

@@ -1119,8 +1109,6 @@ will explain.
11191109
<span class="filename">ファイル名: src/main.rs</span>
11201110

11211111
```rust,ignore
1122-
extern crate rand;
1123-
11241112
use std::io;
11251113
use std::cmp::Ordering;
11261114
use rand::Rng;
@@ -1730,11 +1718,9 @@ secret number. Listing 2-6 shows the final code:
17301718
<span class="filename">ファイル名: src/main.rs</span>
17311719

17321720
```rust,ignore
1733-
extern crate rand;
1734-
1735-
use std::io;
1736-
use std::cmp::Ordering;
17371721
use rand::Rng;
1722+
use std::cmp::Ordering;
1723+
use std::io;
17381724
17391725
fn main() {
17401726
println!("Guess the number!");
@@ -1746,7 +1732,8 @@ fn main() {
17461732
17471733
let mut guess = String::new();
17481734
1749-
io::stdin().read_line(&mut guess)
1735+
io::stdin()
1736+
.read_line(&mut guess)
17501737
.expect("Failed to read line");
17511738
17521739
let guess: u32 = match guess.trim().parse() {

0 commit comments

Comments
 (0)