diff --git a/1.9/ja/book/references-and-borrowing.md b/1.9/ja/book/references-and-borrowing.md index ec41eb9f..541e903b 100644 --- a/1.9/ja/book/references-and-borrowing.md +++ b/1.9/ja/book/references-and-borrowing.md @@ -35,11 +35,12 @@ - + Rustは安全性とスピートに焦点を合わせます。 -Rustはそれらの目標をたくさんの「ゼロコスト抽象化」を通じて成し遂げます。それは、Rustでは抽象化を機能させるためのコストをできる限り小さくすることを意味します。 +Rustはそれらの目標を、様々な「ゼロコスト抽象化」を通じて成し遂げます。 +それは、Rustでは抽象化を機能させるためのコストをできる限り小さくすることを意味します。 所有権システムはゼロコスト抽象化の主な例です。 このガイドの中で話すであろう解析の全ては _コンパイル時に行われます_ 。 それらのどの機能に対しても実行時のコストは全く掛かりません。 @@ -54,9 +55,11 @@ Rustはそれらの目標をたくさんの「ゼロコスト抽象化」を通 しかし、このシステムはあるコストを持ちます。それは学習曲線です。 -多くの新しいRustのユーザは「借用チェッカとの戦い」と好んで呼ばれるものを経験します。そこではRustコンパイラが開発者が正しいと考えるプログラムをコンパイルすることを拒絶します。 +多くのRust入門者は、私たちが「借用チェッカとの戦い」と呼ぶものを経験します。 +そこではRustコンパイラが、開発者が正しいと考えるプログラムをコンパイルすることを拒絶します。 所有権がどのように機能するのかについてのプログラマのメンタルモデルがRustの実装する実際のルールにマッチしないため、これはしばしば起きます。 -しかし、よいニュースがあります。より経験豊富なRustの開発者は次のことを報告します。一度彼らが所有権システムのルールとともにしばらく仕事をすれば、彼らが借用チェッカと戦うことは少なくなっていくということです。 +しかし、よいニュースがあります。より経験豊富なRustの開発者は次のことを報告します。 +それは、所有権システムのルールと共にしばらく仕事をすれば、借用チェッカと戦うことは次第に少なくなっていく、というものです。 それを念頭に置いて、借用について学びましょう。 @@ -120,9 +123,9 @@ let answer = foo(&v1, &v2); 何かを借用した束縛はそれがスコープから外れるときにリソースを割当解除しません。 これは `foo()` の呼出しの後に元の束縛を再び使うことができることを意味します。 - + -参照は束縛とちょうど同じようにイミュータブルです。 +参照は束縛と同じようにイミュータブルです。 これは `foo()` の中ではベクタは全く変更できないことを意味します。 ```rust,ignore @@ -153,7 +156,7 @@ v.push(5); 参照には2つ目の種類、 `&mut T` があります。 -「ミュータブルな参照」によって借用しているリソースを変更することができるようになります。 +「ミュータブルな参照」によって借用しているリソースを変更できるようになります。 例は次のとおりです。 ```rust @@ -168,22 +171,22 @@ println!("{}", x); -これは `6` をプリントするでしょう。 +これは `6` を表示するでしょう。 `y` を `x` へのミュータブルな参照にして、それから `y` の指示先に1を足します。 `x` も `mut` とマークしなければならないことに気付くでしょう。 そうしないと、イミュータブルな値へのミュータブルな借用ということになってしまい、使うことができなくなってしまいます。 - + アスタリスク( `*` )を `y` の前に追加して、それを `*y` にしたことにも気付くでしょう。これは、 `y` が `&mut` 参照だからです。 参照の内容にアクセスするためにもそれらを使う必要があるでしょう。 - + -それ以外は、 `&mut` 参照は普通の参照と全く同じです。 +それ以外は、 `&mut` 参照は普通の参照と同じです。 しかし、2つの間には、そしてそれらがどのように相互作用するかには大きな違いが _あります_ 。 前の例で何かが怪しいと思ったかもしれません。なぜなら、 `{` と `}` を使って追加のスコープを必要とするからです。 もしそれらを削除すれば、次のようなエラーが出ます。 @@ -223,8 +226,8 @@ fn main() { * リソースに対する1つ以上の参照( `&T` ) * ただ1つのミュータブルな参照( `&mut T` ) - - + + これがデータ競合の定義と非常に似ていることに気付くかもしれません。全く同じではありませんが。 @@ -283,11 +286,13 @@ fn main() { ``` - - - -言い換えると、ミュータブルな借用は先程の例の残りの間ずっと保持されるということです。 -必要なものは、 `println!` を呼び出し、イミュータブルな借用を作ろうとする _前に_ 終わるミュータブルな借用です。 + + + + +言い換えると、ミュータブルな借用は、先ほどの例の残りの間、ずっと保持されるということです。 +ここで私たちが求めているのは、`y` によるミュータブルな借用が終わり、リソースがその所有者である `x` に返却されることです。 +そうすれば `x` は `println!` にイミュータブルな借用を提供できるわけです。 Rustでは借用はその有効なスコープと結び付けられます。 そしてスコープはこのように見えます。 @@ -331,9 +336,9 @@ println!("{}", x); // <- ここでxを借用しようとする -問題ありません。 +これなら問題ありません。 ミュータブルな借用はイミュータブルな借用を作る前にスコープから外れます。 -しかしスコープは借用がどれくらい存続するのか理解するための鍵となります。 +しかしスコープは、借用がどれくらい存続するのか理解するための鍵となります。 ## 借用が回避する問題 @@ -362,10 +367,10 @@ for i in &v { } ``` - + -これは1から3までをプリントアウトします。 +これは1から3までを表示します。 ベクタに対して繰り返すとき、要素への参照だけを受け取ります。 そして、 `v` はそれ自体イミュータブルとして借用され、それは繰返しを行っている間はそれを変更できないことを意味します。 diff --git a/diff-1.6.0..1.9.0/src/doc/book/references-and-borrowing.md b/diff-1.6.0..1.9.0/src/doc/book/references-and-borrowing.md deleted file mode 100644 index ad67655e..00000000 --- a/diff-1.6.0..1.9.0/src/doc/book/references-and-borrowing.md +++ /dev/null @@ -1,73 +0,0 @@ ---- a/src/doc/book/references-and-borrowing.md -+++ b/src/doc/book/references-and-borrowing.md -@@ -23,7 +23,7 @@ Before we get to the details, two important notes about the ownership system. - Rust has a focus on safety and speed. It accomplishes these goals through many - ‘zero-cost abstractions’, which means that in Rust, abstractions cost as little - as possible in order to make them work. The ownership system is a prime example --of a zero cost abstraction. All of the analysis we’ll talk about in this guide -+of a zero-cost abstraction. All of the analysis we’ll talk about in this guide - is _done at compile time_. You do not pay any run-time cost for any of these - features. - -@@ -84,7 +84,7 @@ it borrows ownership. A binding that borrows something does not deallocate the - resource when it goes out of scope. This means that after the call to `foo()`, - we can use our original bindings again. - --References are immutable, just like bindings. This means that inside of `foo()`, -+References are immutable, like bindings. This means that inside of `foo()`, - the vectors can’t be changed at all: - - ```rust,ignore -@@ -126,10 +126,10 @@ the thing `y` points at. You’ll notice that `x` had to be marked `mut` as well - If it wasn’t, we couldn’t take a mutable borrow to an immutable value. - - You'll also notice we added an asterisk (`*`) in front of `y`, making it `*y`, --this is because `y` is an `&mut` reference. You'll also need to use them for -+this is because `y` is a `&mut` reference. You'll also need to use them for - accessing the contents of a reference as well. - --Otherwise, `&mut` references are just like references. There _is_ a large -+Otherwise, `&mut` references are like references. There _is_ a large - difference between the two, and how they interact, though. You can tell - something is fishy in the above example, because we need that extra scope, with - the `{` and `}`. If we remove them, we get an error: -@@ -163,8 +163,8 @@ both at the same time: - * exactly one mutable reference (`&mut T`). - - --You may notice that this is very similar, though not exactly the same as, --to the definition of a data race: -+You may notice that this is very similar to, though not exactly the same as, -+the definition of a data race: - - > There is a ‘data race’ when two or more pointers access the same memory - > location at the same time, where at least one of them is writing, and the -@@ -211,9 +211,10 @@ fn main() { - ``` - - In other words, the mutable borrow is held through the rest of our example. What --we want is for the mutable borrow to end _before_ we try to call `println!` and --make an immutable borrow. In Rust, borrowing is tied to the scope that the --borrow is valid for. And our scopes look like this: -+we want is for the mutable borrow by `y` to end so that the resource can be -+returned to the owner, `x`. `x` can then provide a immutable borrow to `println!`. -+In Rust, borrowing is tied to the scope that the borrow is valid for. And our -+scopes look like this: - - ```rust,ignore - let mut x = 5; -@@ -263,7 +264,7 @@ for i in &v { - } - ``` - --This prints out one through three. As we iterate through the vectors, we’re -+This prints out one through three. As we iterate through the vector, we’re - only given references to the elements. And `v` is itself borrowed as immutable, - which means we can’t change it while we’re iterating: - -@@ -378,4 +379,3 @@ statement 1 at 3:14 - - In the above example, `y` is declared before `x`, meaning that `y` lives longer - than `x`, which is not allowed. -- -diff --git a/src/doc/book/rust-inside-other-languages.md b/src/doc/book/rust-inside-other-languages.md