3
3
4
4
<!-- Virtually every non-'Hello World’ Rust program uses *variable bindings*. They -->
5
5
<!-- bind some value to a name, so it can be used later. `let` is -->
6
- <!-- used to introduce a binding, just like this: -->
6
+ <!-- used to introduce a binding, like this: -->
7
7
事実上全ての「Hello World」でないRustのプログラムは * 変数束縛* を使っています。
8
8
変数束縛は何らかの値を名前へと束縛するので、後でその値を使えます。
9
9
このように、 ` let ` が束縛を導入するのに使われています。
@@ -28,23 +28,23 @@ fn main() {
28
28
29
29
<!-- In many languages, a variable binding would be called a *variable*, but Rust’s -->
30
30
<!-- variable bindings have a few tricks up their sleeves. For example the -->
31
- <!-- left-hand side of a `let` expression is a ‘[pattern][pattern]’, not just a -->
31
+ <!-- left-hand side of a `let` statement is a ‘[pattern][pattern]’, not just a -->
32
32
<!-- variable name. This means we can do things like: -->
33
33
多くの言語では変数束縛は * 変数* と呼ばれるでしょうが、Rustの変数束縛は多少皮を被せてあります。
34
- 例えば、 ` let ` の左側の式は 「[ パターン] [ pattern ] 」であって、ただの変数名ではありません。
35
- これはこのようなことが出来るということです 。
34
+ 例えば、 ` let ` 文の左側は 「[ パターン] [ pattern ] 」であって、ただの変数名ではありません。
35
+ これはこのようなことができるということです 。
36
36
37
37
``` rust
38
38
let (x , y ) = (1 , 2 );
39
39
```
40
40
41
- <!-- After this expression is evaluated, `x` will be one, and `y` will be two. -->
41
+ <!-- After this statement is evaluated, `x` will be one, and `y` will be two. -->
42
42
<!-- Patterns are really powerful, and have [their own section][pattern] in the -->
43
- <!-- book. We don’t need those features for now, so we’ll just keep this in the back -->
43
+ <!-- book. We don’t need those features for now, so we’ll keep this in the back -->
44
44
<!-- of our minds as we go forward. -->
45
- パターン式が評価されたあと 、 ` x ` は1になり、 ` y ` は2になります。
45
+ この文が評価されたあと 、 ` x ` は1になり、 ` y ` は2になります。
46
46
パターンは本当に強力で、本書には[ パターンのセクション] [ pattern ] もあります。
47
- 今のところこの機能は必要ないので頭の片隅に留めておいてだけいて下さい 。
47
+ 今のところこの機能は必要ないので頭の片隅に留めておいてだけいてください 。
48
48
49
49
[ pattern ] : patterns.html
50
50
@@ -58,10 +58,10 @@ let (x, y) = (1, 2);
58
58
<!-- out. -->
59
59
Rustは静的な型付言語であり、前もって型を与えておいて、それがコンパイル時に検査されます。
60
60
じゃあなぜ最初の例はコンパイルが通るのでしょう?ええと、Rustには「型推論」と呼ばれるものがあります。
61
- 型推論が型が何であるか判断出来るなら 、型を書く必要はなくなります。
61
+ 型推論が型が何であるか判断できるなら 、型を書く必要はなくなります。
62
62
63
63
<!-- We can add the type if we want to, though. Types come after a colon (`:`): -->
64
- 書きたいなら型を書くことも出来ます 。型はコロン(` : ` )のあとに書きます。
64
+ 書きたいなら型を書くこともできます 。型はコロン(` : ` )のあとに書きます。
65
65
66
66
``` rust
67
67
let x : i32 = 5 ;
@@ -94,7 +94,7 @@ fn main() {
94
94
<!-- `let`. Including these kinds of comments is not idiomatic Rust, but we'll -->
95
95
<!-- occasionally include them to help you understand what the types that Rust -->
96
96
<!-- infers are. -->
97
- この注釈と ` let ` の時に使う記法の類似性に留意して下さい 。
97
+ この注釈と ` let ` の時に使う記法の類似性に留意してください 。
98
98
このようなコメントを書くのはRust的ではありませんが、時折理解の手助けのためにRustが推論する型をコメントで注釈します。
99
99
100
100
<!-- # Mutability -->
@@ -136,7 +136,7 @@ x = 10;
136
136
<!-- something you may not have intended to mutate. If bindings were mutable by -->
137
137
<!-- default, the compiler would not be able to tell you this. If you _did_ intend -->
138
138
<!-- mutation, then the solution is quite easy: add `mut`. -->
139
- 束縛がデフォルトでイミュータブルであるのは複合的な理由によるものですが、Rustの主要な焦点、安全性の一環だと考えることが出来ます 。
139
+ 束縛がデフォルトでイミュータブルであるのは複合的な理由によるものですが、Rustの主要な焦点、安全性の一環だと考えることができます 。
140
140
もし ` mut ` を忘れたらコンパイラが捕捉して、変更するつもりでなかったものを変更した旨を教えてくれます。
141
141
束縛がデフォルトでミュータブルだったらコンパイラはこれを捕捉できません。
142
142
もし _ 本当に_ 変更を意図していたのなら話は簡単です。 ` mut ` をつけ加えればいいのです。
@@ -158,7 +158,7 @@ x = 10;
158
158
Rustの束縛はもう1つ他の言語と異る点があります。束縛を使う前に値で初期化されている必要があるのです。
159
159
160
160
<!-- Let’s try it out. Change your `src/main.rs` file to look like this: -->
161
- 試してみましょう。 ` src/main.rs ` をいじってこのようにしてみて下さい 。
161
+ 試してみましょう。 ` src/main.rs ` をいじってこのようにしてみてください 。
162
162
163
163
``` rust
164
164
fn main () {
@@ -170,8 +170,8 @@ fn main() {
170
170
171
171
<!-- You can use `cargo build` on the command line to build it. You’ll get a -->
172
172
<!-- warning, but it will still print "Hello, world!": -->
173
- コマンドラインで ` cargo build ` を使ってビルド出来ます 。
174
- 警告が出ますが、それでもまだ「Hello, world!」は印字されます 。
173
+ コマンドラインで ` cargo build ` を使ってビルドできます 。
174
+ 警告が出ますが、それでもまだ「Hello, world!」は表示されます 。
175
175
176
176
``` text
177
177
Compiling hello_world v0.0.1 (file:///home/you/projects/hello_world)
@@ -186,7 +186,7 @@ src/main.rs:2 let x: i32;
186
186
<!-- however. Let’s do that. Change your program to look like this: -->
187
187
Rustは一度も使われない変数について警告を出しますが、一度も使われないので人畜無害です。
188
188
ところがこの ` x ` を使おうとすると事は一変します。やってみましょう。
189
- プログラムをこのように変更して下さい 。
189
+ プログラムをこのように変更してください 。
190
190
191
191
``` rust,ignore
192
192
fn main() {
@@ -197,7 +197,7 @@ fn main() {
197
197
```
198
198
199
199
<!-- And try to build it. You’ll get an error: -->
200
- そしてビルドしてみて下さい。このようなエラーが出る筈です 。
200
+ そしてビルドしてみてください。このようなエラーが出るはずです 。
201
201
202
202
``` bash
203
203
$ cargo build
@@ -224,20 +224,20 @@ Rustでは未初期化の値を使うことは許されていません。
224
224
<!-- in the middle of a string." We add a comma, and then `x`, to indicate that we -->
225
225
<!-- want `x` to be the value we’re interpolating. The comma is used to separate -->
226
226
<!-- arguments we pass to functions and macros, if you’re passing more than one. -->
227
- 印字する文字列に2つの波括弧 (` {} ` 、口髭という人もいます…(訳注: 海外の顔文字は横になっているので首を傾けて ` { ` を眺めてみて下さい 。また、日本語だと「中括弧」と呼ぶ人もいますね))を入れました。
228
- Rustはこれを何かの値を入れて (interpolate、インターポーレート)くれという要求だと解釈します 。
229
- * 文字列インターポーレーション * (String interpolation)はコンピュータサイエンスの用語で、「文字列の中に差し込む 」という意味です。
230
- その後に続けてカンマ、そして ` x ` を置いて ` x ` がインターポーレートしようとしている値だと指示しています 。
227
+ 表示する文字列に2つの波括弧 (` {} ` 、口髭という人もいます…(訳注: 海外の顔文字は横になっているので首を傾けて ` { ` を眺めてみてください 。また、日本語だと「中括弧」と呼ぶ人もいますね))を入れました。
228
+ Rustはこれを、何かの値で補間 (interpolate)してほしいのだと解釈します 。
229
+ * 文字列補間 * (string interpolation)はコンピュータサイエンスの用語で、「文字列の間に差し込む 」という意味です。
230
+ その後に続けてカンマ、そして ` x ` を置いて、 ` x ` が補間に使う値だと指示しています 。
231
231
カンマは2つ以上の引数を関数やマクロに渡す時に使われます。
232
232
233
- <!-- When you just use the curly braces, Rust will attempt to display the value in a -->
233
+ <!-- When you use the curly braces, Rust will attempt to display the value in a -->
234
234
<!-- meaningful way by checking out its type. If you want to specify the format in a -->
235
235
<!-- more detailed manner, there are a [wide number of options available][format]. -->
236
- <!-- For now, we'll just stick to the default: integers aren't very complicated to -->
236
+ <!-- For now, we'll stick to the default: integers aren't very complicated to -->
237
237
<!-- print. -->
238
- 単に波括弧だけを使った時は、Rustはインターポーレートされる値の型を調べて意味のある方法で表示しようとします 。
239
- フォーマットをさらに詳しく指定したいなら[ 数多くのオプションが利用出来ます ] [ format ] 。
240
- とりあえずのところ、デフォルトに従いましょう。整数の印字はそれほど複雑ではありません 。
238
+ 波括弧を使うと、Rustは補間に使う値の型を調べて意味のある方法で表示しようとします 。
239
+ フォーマットをさらに詳しく指定したいなら[ 数多くのオプションが利用できます ] [ format ] 。
240
+ とりあえずのところ、デフォルトに従いましょう。整数の表示はそれほど複雑ではありません 。
241
241
242
242
[ format ] : ../std/fmt/index.html
243
243
@@ -253,7 +253,7 @@ Rustはこれを何かの値を入れて(interpolate、インターポーレー
253
253
束縛に話を戻しましょう。変数束縛にはスコープがあります。変数束縛は定義されたブロック内でしか有効でありません。
254
254
ブロックは ` { ` と ` } ` に囲まれた文の集まりです。関数定義もブロックです!
255
255
以下の例では異なるブロックで有効な2つの変数束縛、 ` x ` と ` y ` を定義しています。
256
- ` x ` は ` fn main() {} ` ブロックの中でアクセス可能ですが、 ` y ` は内側のブロックからのみアクセス出来ます 。
256
+ ` x ` は ` fn main() {} ` ブロックの中でアクセス可能ですが、 ` y ` は内側のブロックからのみアクセスできます 。
257
257
258
258
259
259
``` rust,ignore
@@ -272,8 +272,8 @@ fn main() {
272
272
<!-- 3", but this example cannot be compiled successfully, because the second -->
273
273
<!-- `println!` cannot access the value of `y`, since it is not in scope anymore. -->
274
274
<!-- Instead we get this error: -->
275
- 最初の ` println! ` は「The value of x is 17 and the value of y is 3」(訳注: 「xの値は17でyの値は3」)と印字する筈ですが 、
276
- 2つめの ` println! ` は ` y ` がもうスコープにいないため ` y ` にアクセス出来ないのでこの例はコンパイル出来ません 。
275
+ 最初の ` println! ` は「The value of x is 17 and the value of y is 3」(訳注: 「xの値は17でyの値は3」)と表示するはずですが 、
276
+ 2つめの ` println! ` は ` y ` がもうスコープにいないため ` y ` にアクセスできないのでこの例はコンパイルできません 。
277
277
代わりに以下のようなエラーが出ます。
278
278
279
279
``` bash
@@ -298,31 +298,31 @@ To learn more, run the command again with --verbose.
298
298
<!-- Additionally, variable bindings can be shadowed. This means that a later -->
299
299
<!-- variable binding with the same name as another binding, that's currently in -->
300
300
<!-- scope, will override the previous binding. -->
301
- さらに加えて、変数束縛は覆い隠すことが出来ます (訳注: このことをシャドーイングと言います)。
301
+ さらに加えて、変数束縛は覆い隠すことができます (訳注: このことをシャドーイングと言います)。
302
302
つまり後に出てくる同じ名前の変数束縛があるとそれがスコープに入り、以前の束縛を上書きするのです。
303
303
304
304
``` rust
305
305
let x : i32 = 8 ;
306
306
{
307
307
# // println!("{}", x); // Prints "8"
308
- println! (" {}" , x ); // "8"を印字する
308
+ println! (" {}" , x ); // "8"を表示する
309
309
let x = 12 ;
310
310
# // println!("{}", x); // Prints "12"
311
- println! (" {}" , x ); // "12"を印字する
311
+ println! (" {}" , x ); // "12"を表示する
312
312
}
313
313
# // println!("{}", x); // Prints "8"
314
- println! (" {}" , x ); // "8"を印字する
314
+ println! (" {}" , x ); // "8"を表示する
315
315
let x = 42 ;
316
316
# // println!("{}", x); // Prints "42"
317
- println! (" {}" , x ); // "42"を印字する
317
+ println! (" {}" , x ); // "42"を表示する
318
318
```
319
319
320
320
<!-- Shadowing and mutable bindings may appear as two sides of the same coin, but -->
321
321
<!-- they are two distinct concepts that can't always be used interchangeably. For -->
322
322
<!-- one, shadowing enables us to rebind a name to a value of a different type. It -->
323
323
<!-- is also possible to change the mutability of a binding. -->
324
- シャドーイングとミュータブルな束縛はコインの表と裏のように見えるかもしれませんが、それぞれ独立な概念であり互いに代用が出来ないケースがあります 。
325
- その1つにシャドーイングは同じ名前に違う型の値を再束縛することが出来ます 。
324
+ シャドーイングとミュータブルな束縛はコインの表と裏のように見えるかもしれませんが、それぞれ独立な概念であり互いに代用ができないケースがあります 。
325
+ その1つにシャドーイングは同じ名前に違う型の値を再束縛することができます 。
326
326
327
327
``` rust
328
328
let mut x : i32 = 1 ;
0 commit comments