Skip to content

Commit 56ded8b

Browse files
committed
translate mutability.md (and update TranslationTable)
1 parent 76cc246 commit 56ded8b

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

1.6/ja/book/mutability.md

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
<!-- than in other languages. The first aspect of mutability is its non-default -->
66
<!-- status: -->
77
Rustにおけるミュータビリティ、何かを変更する能力は、他のプログラミング言語とはすこし異なっています。
8-
ミュータビリティの一つ目の特徴は、デフォルトでは無いという点です:
8+
ミュータビリティの一つ目の特徴は、それがデフォルトでは無いという点です:
99

1010
```rust,ignore
1111
let x = 5;
12-
x = 6; // error!
12+
# // x = 6; // error!
13+
x = 6; // エラー!
1314
```
1415

1516
<!-- We can introduce mutability with the `mut` keyword: -->
@@ -18,20 +19,21 @@ x = 6; // error!
1819
```rust
1920
let mut x = 5;
2021

21-
x = 6; // no problem!
22+
# // x = 6; // no problem!
23+
x = 6; // 問題なし!
2224
```
2325

2426
<!-- This is a mutable [variable binding][vb]. When a binding is mutable, it means -->
2527
<!-- you’re allowed to change what the binding points to. So in the above example, -->
2628
<!-- it’s not so much that the value at `x` is changing, but that the binding -->
2729
<!-- changed from one `i32` to another. -->
28-
これはミュータブルな [変数束縛][vb] です。束縛がミュータブルのとき、束縛が何を指すかを変更して良いことを意味します
29-
つまり上記の例では、 `x` の値を変更したのではなく、束縛がある `i32` から別のものへ変わったのです
30+
これはミュータブルな [変数束縛][vb] です。束縛がミュータブルであるとき、その束縛が何を指すかを変更して良いことを意味します
31+
つまり上記の例では、`x` の値を変更したのではなく、ある `i32` から別の値へと束縛が変わったのです
3032

3133
[vb]: variable-bindings.html
3234

3335
<!-- If you want to change what the binding points to, you’ll need a [mutable reference][mr]: -->
34-
束縛先を変更したいのであれば、 [ミュータブル参照][mr] を使うことができます:
36+
束縛が指す先を変更する場合は、[ミュータブル参照][mr] を使う必要があるでしょう:
3537

3638
```rust
3739
let mut x = 5;
@@ -43,7 +45,7 @@ let y = &mut x;
4345
<!-- `y` is an immutable binding to a mutable reference, which means that you can’t -->
4446
<!-- bind `y` to something else (`y = &mut z`), but you can mutate the thing that’s -->
4547
<!-- bound to `y` (`*y = 5`). A subtle distinction. -->
46-
`y` はミュータブル参照へのイミュータブル束縛であり`y` の束縛先を他のものに変える(`y = &mut z`)ことはできません。
48+
`y` はミュータブル参照へのイミュータブルな束縛であり`y` を他の束縛に変える(`y = &mut z`)ことはできません。
4749
しかし、`y` に束縛されているものを変化させること(`*y = 5`)は可能です。
4850

4951
<!-- Of course, if you need both: -->
@@ -60,8 +62,8 @@ let mut y = &mut x;
6062

6163
<!-- It’s important to note that `mut` is part of a [pattern][pattern], so you -->
6264
<!-- can do things like this: -->
63-
`mut`[パターン][pattern] の一部であることに十分注意してください
64-
つまり、次のようなことを行えます:
65+
`mut`[パターン][pattern] の一部を成すことに十分注意してください
66+
つまり、次のようなことが可能です:
6567

6668
```rust
6769
let (mut x, y) = (5, 6);
@@ -79,7 +81,7 @@ fn foo(mut x: i32) {
7981
<!-- it’s not able to be changed: we mean something has ‘exterior mutability’. Consider, -->
8082
<!-- for example, [`Arc<T>`][arc]: -->
8183
一方で、Rustで「イミュータブル(immutable)」について言及するとき、変更不可能であることを意味しない:
82-
「外側のミュータビリティ(exterior mutability)」を表します。例として、 [`Arc<T>`][arc] を考えます:
84+
「外側のミュータビリティ(exterior mutability)」を表します。例として、[`Arc<T>`][arc] を考えます:
8385

8486
```rust
8587
use std::sync::Arc;
@@ -94,13 +96,13 @@ let y = x.clone();
9496
<!-- we’ve not used any `mut`s here, `x` is an immutable binding, and we didn’t take -->
9597
<!-- `&mut 5` or anything. So what gives? -->
9698
`clone()` を呼び出すとき、`Arc<T>` は参照カウントを更新する必要があります。しかし、
97-
ここでは `mut` を一切使っていません。つまり `x` はイミュータブル束縛であり
98-
`&mut 5` のような引数もとりません。一体どうなっているの
99+
ここでは `mut` を一切使っていません。つまり `x` はイミュータブルな束縛であり
100+
`&mut 5` のような引数もとりません。一体どうなっているの?
99101

100102
<!-- To understand this, we have to go back to the core of Rust’s guiding -->
101103
<!-- philosophy, memory safety, and the mechanism by which Rust guarantees it, the -->
102104
<!-- [ownership][ownership] system, and more specifically, [borrowing][borrowing]: -->
103-
これを理解するには、Rust言語の設計哲学の中心をなすメモリ安全性、Rustがそれを保証するメカニズムである [所有権][ownership] システム、
105+
これを理解するには、Rust言語の設計哲学の中心をなすメモリ安全性と、Rustがそれを保証するメカニズムである [所有権][ownership] システム、
104106
特に [借用][borrowing] に立ち返る必要があります。
105107

106108
<!-- > You may have one or the other of these two kinds of borrows, but not both at -->
@@ -120,14 +122,15 @@ let y = x.clone();
120122
<!-- pointers to? In `Arc<T>`’s case, yes: the mutation is entirely contained inside -->
121123
<!-- the structure itself. It’s not user facing. For this reason, it hands out `&T` -->
122124
<!-- with `clone()`. If it handed out `&mut T`s, though, that would be a problem. -->
123-
つまり、「イミュータビリティ」の真の定義はこうです: これは2つから指されても安全か?
124-
`Arc<T>` の例では、イエス: 変更は完全それ自身の構造の内側で行われます。ユーザ向いではありません。
125+
つまり、「イミュータビリティ」の真の定義はこうです: これは2箇所から指されても安全ですか?
126+
`Arc<T>` の例では、イエス: 変更は完全にそれ自身の構造の内側で行われます。ユーザ向いではありません。
125127
このような理由により、 `clone()` を用いて `T&` を配るのです。仮に `&mut T` を配ってしまうと、
126-
問題になるでしょう。(訳注: `Arc<T>`を用いて複数スレッドへイミュータブルな値を配布する。)
128+
問題になるでしょう。
129+
(訳注: `Arc<T>`を用いて複数スレッドにイミュータブル参照を配布し、スレッド間でオブジェクトを共有できます。)
127130

128131
<!-- Other types, like the ones in the [`std::cell`][stdcell] module, have the -->
129132
<!-- opposite: interior mutability. For example: -->
130-
[`std::cell`][stdcell] モジュール中の他の型は、反対の性質: 内側のミュータビリティを持ちます
133+
[`std::cell`][stdcell] モジュールにあるような別の型では、反対の性質: 内側のミュータビリティ(interior mutability)を持ちます
131134
例えば:
132135

133136
```rust
@@ -140,8 +143,10 @@ let y = x.borrow_mut();
140143

141144
[stdcell]: ../std/cell/index.html
142145

143-
RefCell hands out `&mut` references to what’s inside of it with the
144-
`borrow_mut()` method. Isn’t that dangerous? What if we do:
146+
<!-- RefCell hands out `&mut` references to what’s inside of it with the -->
147+
<!-- `borrow_mut()` method. Isn’t that dangerous? What if we do: -->
148+
RefCellでは `borrow_mut()` メソッドによって、その内側にある値への `&mut` 参照を配ります。
149+
それって危ないのでは? もし次のようにすると:
145150

146151
```rust,ignore
147152
use std::cell::RefCell;
@@ -153,25 +158,35 @@ let z = x.borrow_mut();
153158
# (y, z);
154159
```
155160

156-
This will in fact panic, at runtime. This is what `RefCell` does: it enforces
157-
Rust’s borrowing rules at runtime, and `panic!`s if they’re violated. This
158-
allows us to get around another aspect of Rust’s mutability rules. Let’s talk
159-
about it first.
161+
<!-- This will in fact panic, at runtime. This is what `RefCell` does: it enforces -->
162+
<!-- Rust’s borrowing rules at runtime, and `panic!`s if they’re violated. This -->
163+
<!-- allows us to get around another aspect of Rust’s mutability rules. Let’s talk -->
164+
<!-- about it first. -->
165+
実際に、このコードは実行時にパニックするでしょう。これが `RefCell` が行うことです:
166+
Rustの借用ルールを実行時に強制し、違反したときには `panic!` を呼び出します。
167+
これによりRustのミュータビリティ・ルールのもう一つの特徴を回避できるようになります。
168+
最初に見ていきましょう。
160169

161-
## Field-level mutability
170+
<!-- ## Field-level mutability -->
171+
## フィールド・レベルのミュータビリティ
172+
173+
<!-- Mutability is a property of either a borrow (`&mut`) or a binding (`let mut`). -->
174+
<!-- This means that, for example, you cannot have a [`struct`][struct] with -->
175+
<!-- some fields mutable and some immutable: -->
176+
ミュータビリティとは、借用(`&mut`)や束縛(`let mut`)に関する属性です。これが意味するのは、
177+
例えば、一部がミュータブルで一部がイミュータブルなフィールドを持つ [`struct`][struct] は作れないということです。
162178

163-
Mutability is a property of either a borrow (`&mut`) or a binding (`let mut`).
164-
This means that, for example, you cannot have a [`struct`][struct] with
165-
some fields mutable and some immutable:
166179

167180
```rust,ignore
168181
struct Point {
169182
x: i32,
170-
mut y: i32, // nope
183+
# // mut y: i32, // nope
184+
mut y: i32, // ダメ
171185
}
172186
```
173187

174-
The mutability of a struct is in its binding:
188+
<!-- The mutability of a struct is in its binding: -->
189+
構造体のミュータビリティは、それへの束縛の一部です。
175190

176191
```rust,ignore
177192
struct Point {
@@ -185,12 +200,14 @@ a.x = 10;
185200
186201
let b = Point { x: 5, y: 6};
187202
188-
b.x = 10; // error: cannot assign to immutable field `b.x`
203+
# // b.x = 10; // error: cannot assign to immutable field `b.x`
204+
b.x = 10; // エラー: イミュータブルなフィールド `b.x` へ代入できない
189205
```
190206

191207
[struct]: structs.html
192208

193-
However, by using [`Cell<T>`][cell], you can emulate field-level mutability:
209+
<!-- However, by using [`Cell<T>`][cell], you can emulate field-level mutability: -->
210+
しかし、[`Cell<T>`][cell] を使えば、フィールド・レベルのミュータビリティをエミュレートできます。
194211

195212
```rust
196213
use std::cell::Cell;
@@ -209,4 +226,5 @@ println!("y: {:?}", point.y);
209226

210227
[cell]: ../std/cell/struct.Cell.html
211228

212-
This will print `y: Cell { value: 7 }`. We’ve successfully updated `y`.
229+
<!-- This will print `y: Cell { value: 7 }`. We’ve successfully updated `y`. -->
230+
このコードは `y: Cell { value: 7 }` と表示するでしょう。ちゃんと `y` を更新できました。

TranslationTable.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
| error | エラー
7070
| error handling | エラーハンドリング
7171
| expression statement | 式文
72+
| exterior | 外側の
7273
| feature | フィーチャ
7374
| foreign | 他言語
7475
| free-standing function | フリースタンディングな関数
@@ -79,9 +80,11 @@
7980
| hash | ハッシュ
8081
| identifier | 識別子
8182
| immutable | イミュータブル
83+
| immutability | イミュータビリティ
8284
| implement | 実装する
8385
| initialize | 初期化する
8486
| input lifetime | 入力ライフタイム
87+
| interior | 内側の
8588
| install | インストール
8689
| installer | インストーラ
8790
| interpolate | インターポーレートする
@@ -133,6 +136,7 @@
133136
| return | 返す
134137
| return type | リターン型
135138
| return value | 戻り値
139+
| runtime | 実行時
136140
| safe | 安全
137141
| safety check | 安全性検査
138142
| scope | スコープ

0 commit comments

Comments
 (0)