From bb1eb5d2ddbfa1ce78f21c48b19175a5c44ace0d Mon Sep 17 00:00:00 2001 From: "Sunrin SHIMURA (keen)" <3han5chou7@gmail.com> Date: Wed, 13 Jul 2016 18:01:38 +0900 Subject: [PATCH] update choosing your guarantees --- 1.9/ja/book/choosing-your-guarantees.md | 15 +++--- .../src/doc/book/choosing-your-guarantees.md | 52 ------------------- 2 files changed, 7 insertions(+), 60 deletions(-) delete mode 100644 diff-1.6.0..1.9.0/src/doc/book/choosing-your-guarantees.md diff --git a/1.9/ja/book/choosing-your-guarantees.md b/1.9/ja/book/choosing-your-guarantees.md index 8a3974ef..d5b5db31 100644 --- a/1.9/ja/book/choosing-your-guarantees.md +++ b/1.9/ja/book/choosing-your-guarantees.md @@ -78,11 +78,11 @@ let y = x; ## `*const T` と `*mut T` - + 関連付けられたライフタイムや所有権を持たない、C的な生ポインタがあります。 -それらはメモリのある場所を何の制約もなく単に指示します。 +それらはメモリのある場所を何の制約もなく指示します。 それらの提供する唯一の保証は、 `unsafe` であるとマークされたコードの外ではそれらが参照を外せないということです。 @@ -284,7 +284,7 @@ let x = RefCell::new(vec![1,2,3,4]); 一般的に、そのような変更はネストした形式では発生しないと考えられますが、それをチェックすることはよいことです。 - + @@ -293,7 +293,7 @@ let x = RefCell::new(vec![1,2,3,4]); 大きく複雑なプログラムにとって、物事を単純にするために何かを `RefCell` の中に入れることは便利です。 -例えば、Rustコンパイラの内部の [`ctxt`構造体][ctxt] にあるたくさんのマップはこのラッパの中にあります。 +例えば、Rustコンパイラの内部の`ctxt`構造体にあるたくさんのマップはこのラッパの中にあります。 それらは(初期化の直後ではなく生成の過程で)一度だけ変更されるか、又はきれいに分離された場所で数回変更されます。 しかし、この構造体はあらゆる場所で全般的に使われているので、ミュータブルなポインタとイミュータブルなポインタとをジャグリング的に扱うのは難しく(あるいは不可能で)、おそらく拡張の困難な `&` ポインタのスープになってしまいます。 一方、 `RefCell` はそれらにアクセスするための(ゼロコストではありませんが)低コストの方法です。 @@ -330,7 +330,6 @@ let x = RefCell::new(vec![1,2,3,4]); [cell-mod]: ../std/cell/ [cell]: ../std/cell/struct.Cell.html [refcell]: ../std/cell/struct.RefCell.html -[ctxt]: ../rustc/middle/ty/struct.ctxt.html # 同期型 @@ -358,7 +357,7 @@ let x = RefCell::new(vec![1,2,3,4]); ## `Arc` - + [`Arc`][arc] はアトミックな参照カウントを使う `Rc` の別バージョンです(そのため、「Arc」なのです)。 これはスレッド間で自由に送ることができます。 @@ -479,7 +478,7 @@ Rustのコードを読むときに一般的な悩みは、 `Rc>>` - + 1つ目について、 `RefCell` は `Vec` をラップしているので、その `Vec` 全体がミュータブルです。 同時に、それらは特定の時間において `Vec` 全体の唯一のミュータブルな借用になり得ます。 これは、コードがそのベクタの別の要素について、別の `Rc` ハンドルから同時には操作できないということを意味します。 @@ -488,7 +487,7 @@ Rustのコードを読むときに一般的な悩みは、 `Rc>>` - + 2つ目について、借用は個々の要素に対して行われますが、ベクタ全体がイミュータブルになります。 そのため、異なる要素を別々に借用することができますが、ベクタに対するプッシュやポップを行うことはできません。 これは `&mut [T]`[^3] と同じですが、やはり借用チェックは実行時に行われます。 diff --git a/diff-1.6.0..1.9.0/src/doc/book/choosing-your-guarantees.md b/diff-1.6.0..1.9.0/src/doc/book/choosing-your-guarantees.md deleted file mode 100644 index a5c5cf9e..00000000 --- a/diff-1.6.0..1.9.0/src/doc/book/choosing-your-guarantees.md +++ /dev/null @@ -1,52 +0,0 @@ ---- a/src/doc/book/choosing-your-guarantees.md -+++ b/src/doc/book/choosing-your-guarantees.md -@@ -52,7 +52,7 @@ These pointers cannot be copied in such a way that they outlive the lifetime ass - - ## `*const T` and `*mut T` - --These are C-like raw pointers with no lifetime or ownership attached to them. They just point to -+These are C-like raw pointers with no lifetime or ownership attached to them. They point to - some location in memory with no other restrictions. The only guarantee that these provide is that - they cannot be dereferenced except in code marked `unsafe`. - -@@ -204,7 +204,7 @@ borrow checker. Generally we know that such mutations won't happen in a nested f - to check. - - For large, complicated programs, it becomes useful to put some things in `RefCell`s to make things --simpler. For example, a lot of the maps in [the `ctxt` struct][ctxt] in the Rust compiler internals -+simpler. For example, a lot of the maps in the `ctxt` struct in the Rust compiler internals - are inside this wrapper. These are only modified once (during creation, which is not right after - initialization) or a couple of times in well-separated places. However, since this struct is - pervasively used everywhere, juggling mutable and immutable pointers would be hard (perhaps -@@ -235,7 +235,6 @@ At runtime each borrow causes a modification/check of the refcount. - [cell-mod]: ../std/cell/ - [cell]: ../std/cell/struct.Cell.html - [refcell]: ../std/cell/struct.RefCell.html --[ctxt]: ../rustc/middle/ty/struct.ctxt.html - - # Synchronous types - -@@ -255,7 +254,7 @@ major ones will be covered below. - - ## `Arc` - --[`Arc`][arc] is just a version of `Rc` that uses an atomic reference count (hence, "Arc"). -+[`Arc`][arc] is a version of `Rc` that uses an atomic reference count (hence, "Arc"). - This can be sent freely between threads. - - C++'s `shared_ptr` is similar to `Arc`, however in the case of C++ the inner data is always mutable. -@@ -340,11 +339,11 @@ With the former, the `RefCell` is wrapping the `Vec`, so the `Vec` in i - mutable. At the same time, there can only be one mutable borrow of the whole `Vec` at a given time. - This means that your code cannot simultaneously work on different elements of the vector from - different `Rc` handles. However, we are able to push and pop from the `Vec` at will. This is --similar to an `&mut Vec` with the borrow checking done at runtime. -+similar to a `&mut Vec` with the borrow checking done at runtime. - - With the latter, the borrowing is of individual elements, but the overall vector is immutable. Thus, - we can independently borrow separate elements, but we cannot push or pop from the vector. This is --similar to an `&mut [T]`[^3], but, again, the borrow checking is at runtime. -+similar to a `&mut [T]`[^3], but, again, the borrow checking is at runtime. - - In concurrent programs, we have a similar situation with `Arc>`, which provides shared - mutability and ownership. -diff --git a/src/doc/book/closures.md b/src/doc/book/closures.md