@@ -227,14 +227,15 @@ <h1 id='概論' class='section-header'><a href='#概論'>概論</a></h1>
227
227
228
228
<!-- as possible in order to make them work. The ownership system is a prime example -->
229
229
230
- <!-- of a zero cost abstraction. All of the analysis we’ll talk about in this guide -->
230
+ <!-- of a zero- cost abstraction. All of the analysis we’ll talk about in this guide -->
231
231
232
232
<!-- is _done at compile time_. You do not pay any run-time cost for any of these -->
233
233
234
234
<!-- features. -->
235
235
236
236
< p > Rustは安全性とスピートに焦点を合わせます。
237
- Rustはそれらの目標をたくさんの「ゼロコスト抽象化」を通じて成し遂げます。それは、Rustでは抽象化を機能させるためのコストをできる限り小さくすることを意味します。
237
+ Rustはそれらの目標を、様々な「ゼロコスト抽象化」を通じて成し遂げます。
238
+ それは、Rustでは抽象化を機能させるためのコストをできる限り小さくすることを意味します。
238
239
所有権システムはゼロコスト抽象化の主な例です。
239
240
このガイドの中で話すであろう解析の全ては < em > コンパイル時に行われます</ em > 。
240
241
それらのどの機能に対しても実行時のコストは全く掛かりません。</ p >
@@ -258,9 +259,11 @@ <h1 id='概論' class='section-header'><a href='#概論'>概論</a></h1>
258
259
<!-- checker less and less. -->
259
260
260
261
< p > しかし、このシステムはあるコストを持ちます。それは学習曲線です。
261
- 多くの新しいRustのユーザは「借用チェッカとの戦い」と好んで呼ばれるものを経験します。そこではRustコンパイラが開発者が正しいと考えるプログラムをコンパイルすることを拒絶します。
262
+ 多くのRust入門者は、私たちが「借用チェッカとの戦い」と呼ぶものを経験します。
263
+ そこではRustコンパイラが、開発者が正しいと考えるプログラムをコンパイルすることを拒絶します。
262
264
所有権がどのように機能するのかについてのプログラマのメンタルモデルがRustの実装する実際のルールにマッチしないため、これはしばしば起きます。
263
- しかし、よいニュースがあります。より経験豊富なRustの開発者は次のことを報告します。一度彼らが所有権システムのルールとともにしばらく仕事をすれば、彼らが借用チェッカと戦うことは少なくなっていくということです。</ p >
265
+ しかし、よいニュースがあります。より経験豊富なRustの開発者は次のことを報告します。
266
+ それは、所有権システムのルールと共にしばらく仕事をすれば、借用チェッカと戦うことは次第に少なくなっていく、というものです。</ p >
264
267
265
268
<!-- With that in mind, let’s learn about borrowing. -->
266
269
@@ -359,11 +362,11 @@ <h1 id='借用' class='section-header'><a href='#借用'>借用</a></h1>
359
362
何かを借用した束縛はそれがスコープから外れるときにリソースを割当解除しません。
360
363
これは < code > foo()</ code > の呼出しの後に元の束縛を再び使うことができることを意味します。</ p >
361
364
362
- <!-- References are immutable, just like bindings. This means that inside of `foo()`, -->
365
+ <!-- References are immutable, like bindings. This means that inside of `foo()`, -->
363
366
364
367
<!-- the vectors can’t be changed at all: -->
365
368
366
- < p > 参照は束縛とちょうど同じようにイミュータブルです 。
369
+ < p > 参照は束縛と同じようにイミュータブルです 。
367
370
これは < code > foo()</ code > の中ではベクタは全く変更できないことを意味します。</ p >
368
371
369
372
< span class ='rusttest '> fn main() {
@@ -404,7 +407,7 @@ <h1 id='mut参照' class='section-header'><a href='#mut参照'>&mut参照</a
404
407
<!-- to mutate the resource you’re borrowing. For example: -->
405
408
406
409
< p > 参照には2つ目の種類、 < code > &mut T</ code > があります。
407
- 「ミュータブルな参照」によって借用しているリソースを変更することができるようになります 。
410
+ 「ミュータブルな参照」によって借用しているリソースを変更できるようになります 。
408
411
例は次のとおりです。</ p >
409
412
410
413
< span class ='rusttest '> fn main() {
@@ -428,29 +431,29 @@ <h1 id='mut参照' class='section-header'><a href='#mut参照'>&mut参照</a
428
431
429
432
<!-- If it wasn’t, we couldn’t take a mutable borrow to an immutable value. -->
430
433
431
- < p > これは < code > 6</ code > をプリントするでしょう 。
434
+ < p > これは < code > 6</ code > を表示するでしょう 。
432
435
< code > y</ code > を < code > x</ code > へのミュータブルな参照にして、それから < code > y</ code > の指示先に1を足します。
433
436
< code > x</ code > も < code > mut</ code > とマークしなければならないことに気付くでしょう。
434
437
そうしないと、イミュータブルな値へのミュータブルな借用ということになってしまい、使うことができなくなってしまいます。</ p >
435
438
436
439
<!-- You'll also notice we added an asterisk (`*`) in front of `y`, making it `*y`, -->
437
440
438
- <!-- this is because `y` is an `&mut` reference. You'll also need to use them for -->
441
+ <!-- this is because `y` is a `&mut` reference. You'll also need to use them for -->
439
442
440
443
<!-- accessing the contents of a reference as well. -->
441
444
442
445
< p > アスタリスク( < code > *</ code > )を < code > y</ code > の前に追加して、それを < code > *y</ code > にしたことにも気付くでしょう。これは、 < code > y</ code > が < code > &mut</ code > 参照だからです。
443
446
参照の内容にアクセスするためにもそれらを使う必要があるでしょう。</ p >
444
447
445
- <!-- Otherwise, `&mut` references are just like references. There _is_ a large -->
448
+ <!-- Otherwise, `&mut` references are like references. There _is_ a large -->
446
449
447
450
<!-- difference between the two, and how they interact, though. You can tell -->
448
451
449
452
<!-- something is fishy in the above example, because we need that extra scope, with -->
450
453
451
454
<!-- the `{` and `}`. If we remove them, we get an error: -->
452
455
453
- < p > それ以外は、 < code > &mut</ code > 参照は普通の参照と全く同じです 。
456
+ < p > それ以外は、 < code > &mut</ code > 参照は普通の参照と同じです 。
454
457
しかし、2つの間には、そしてそれらがどのように相互作用するかには大きな違いが < em > あります</ em > 。
455
458
前の例で何かが怪しいと思ったかもしれません。なぜなら、 < code > {</ code > と < code > }</ code > を使って追加のスコープを必要とするからです。
456
459
もしそれらを削除すれば、次のようなエラーが出ます。</ p >
@@ -498,9 +501,9 @@ <h1 id='ルール' class='section-header'><a href='#ルール'>ルール</a></h1
498
501
< li > ただ1つのミュータブルな参照( < code > &mut T</ code > )</ li >
499
502
</ ul >
500
503
501
- <!-- You may notice that this is very similar, though not exactly the same as, -->
504
+ <!-- You may notice that this is very similar to , though not exactly the same as, -->
502
505
503
- <!-- to the definition of a data race: -->
506
+ <!-- the definition of a data race: -->
504
507
505
508
< p > これがデータ競合の定義と非常に似ていることに気付くかもしれません。全く同じではありませんが。</ p >
506
509
@@ -580,14 +583,17 @@ <h2 id='スコープの考え方' class='section-header'><a href='#スコープ
580
583
581
584
<!-- In other words, the mutable borrow is held through the rest of our example. What -->
582
585
583
- <!-- we want is for the mutable borrow to end _before_ we try to call `println!` and -->
586
+ <!-- we want is for the mutable borrow by `y` to end so that the resource can be -->
584
587
585
- <!-- make an immutable borrow. In Rust, borrowing is tied to the scope that the -->
588
+ <!-- returned to the owner, `x`. `x` can then provide a immutable borrow to `println!`. -->
586
589
587
- <!-- borrow is valid for. And our scopes look like this: -->
590
+ <!-- In Rust, borrowing is tied to the scope that the borrow is valid for. And our -->
588
591
589
- < p > 言い換えると、ミュータブルな借用は先程の例の残りの間ずっと保持されるということです。
590
- 必要なものは、 < code > println!</ code > を呼び出し、イミュータブルな借用を作ろうとする < em > 前に</ em > 終わるミュータブルな借用です。
592
+ <!-- scopes look like this: -->
593
+
594
+ < p > 言い換えると、ミュータブルな借用は、先ほどの例の残りの間、ずっと保持されるということです。
595
+ ここで私たちが求めているのは、< code > y</ code > によるミュータブルな借用が終わり、リソースがその所有者である < code > x</ code > に返却されることです。
596
+ そうすれば < code > x</ code > は < code > println!</ code > にイミュータブルな借用を提供できるわけです。
591
597
Rustでは借用はその有効なスコープと結び付けられます。
592
598
そしてスコープはこのように見えます。</ p >
593
599
@@ -651,9 +657,9 @@ <h2 id='スコープの考え方' class='section-header'><a href='#スコープ
651
657
652
658
<!-- immutable one. But scope is the key to seeing how long a borrow lasts for. -->
653
659
654
- < p > 問題ありません 。
660
+ < p > これなら問題ありません 。
655
661
ミュータブルな借用はイミュータブルな借用を作る前にスコープから外れます。
656
- しかしスコープは借用がどれくらい存続するのか理解するための鍵となります 。</ p >
662
+ しかしスコープは、借用がどれくらい存続するのか理解するための鍵となります 。</ p >
657
663
658
664
<!-- ## Issues borrowing prevents -->
659
665
@@ -692,13 +698,13 @@ <h3 id='イテレータの無効' class='section-header'><a href='#イテレー
692
698
< span class ='macro '> println</ span > < span class ='macro '> !</ span > (< span class ='string '> "{}"</ span > , < span class ='ident '> i</ span > );
693
699
}</ pre >
694
700
695
- <!-- This prints out one through three. As we iterate through the vectors , we’re -->
701
+ <!-- This prints out one through three. As we iterate through the vector , we’re -->
696
702
697
703
<!-- only given references to the elements. And `v` is itself borrowed as immutable, -->
698
704
699
705
<!-- which means we can’t change it while we’re iterating: -->
700
706
701
- < p > これは1から3までをプリントアウトします 。
707
+ < p > これは1から3までを表示します 。
702
708
ベクタに対して繰り返すとき、要素への参照だけを受け取ります。
703
709
そして、 < code > v</ code > はそれ自体イミュータブルとして借用され、それは繰返しを行っている間はそれを変更できないことを意味します。</ p >
704
710
0 commit comments