Skip to content

Commit 855e3d4

Browse files
committed
ci: generate pages at 557d71f [ci skip]
1 parent 557d71f commit 855e3d4

File tree

4 files changed

+56
-70
lines changed

4 files changed

+56
-70
lines changed

docs/ch15-02-deref.html

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,15 @@ <h3><a class="header" href="#独自のスマートポインタを定義する" i
309309
references by default. Then we’ll look at how to add the ability to use the
310310
dereference operator.
311311
-->
312-
<p>標準ライブラリが提供している<code>Box&lt;T&gt;</code>型に似たスマートポインタを構築して、スマートポインタは既定で
313-
参照に比べてどう異なって振る舞うのか経験しましょう。それから、参照外し演算子を使う能力を追加する方法に目を向けましょう</p>
312+
<p>標準ライブラリが提供している<code>Box&lt;T&gt;</code>型に似たスマートポインタを作りましょう。そうすれば、スマートポインタがそのままだと
313+
参照と同じ様には振る舞わないことがわかります。それから、どうすれば参照外し演算子を使えるようになるのか見てみましょう</p>
314314
<!--
315315
The `Box<T>` type is ultimately defined as a tuple struct with one element, so
316316
Listing 15-8 defines a `MyBox<T>` type in the same way. We’ll also define a
317317
`new` function to match the `new` function defined on `Box<T>`.
318318
-->
319-
<p><code>Box&lt;T&gt;</code>型は究極的に1要素のタプル構造体として定義されているので、リスト15-8は、同じように<code>MyBox&lt;T&gt;</code>型を定義しています。
320-
また、<code>Box&lt;T&gt;</code>に定義された<code>new</code>関数と合致する<code>new</code>関数も定義しています。</p>
319+
<p><code>Box&lt;T&gt;</code>型は突き詰めると(訳註:データがヒープに置かれることを無視すると)1要素のタプル構造体のような定義になります。なのでリスト15-8ではそのように<code>MyBox&lt;T&gt;</code>型を定義しています。
320+
また、<code>Box&lt;T&gt;</code>に定義された<code>new</code>関数に対応する<code>new</code>関数も定義しています。</p>
321321
<!--
322322
<span class="filename">Filename: src/main.rs</span>
323323
-->
@@ -344,16 +344,16 @@ <h3><a class="header" href="#独自のスマートポインタを定義する" i
344344
with one element of type `T`. The `MyBox::new` function takes one parameter of
345345
type `T` and returns a `MyBox` instance that holds the value passed in.
346346
-->
347-
<p><code>MyBox</code>という構造体を定義し、ジェネリック引数の<code>T</code>を宣言しています。自分の型にどんな型の値も保持させたいからです
348-
<code>MyBox</code>型は、型<code>T</code>を1要素持つタプル構造体です<code>MyBox::new</code>関数は型<code>T</code>の引数を1つ取り、
349-
渡した値を保持する<code>MyBox</code>インスタンスを返します</p>
347+
<p><code>MyBox</code>という構造体を定義し、ジェネリック引数の<code>T</code>を宣言しています。この型にどんな型の値も持たせたいからです
348+
<code>MyBox</code>型は型<code>T</code>の要素を1つ持つタプル構造体です<code>MyBox::new</code>関数は型<code>T</code>の引数を1つ取り、
349+
渡した値を持つ<code>MyBox</code>のインスタンスを返します</p>
350350
<!--
351351
Let’s try adding the `main` function in Listing 15-7 to Listing 15-8 and
352352
changing it to use the `MyBox<T>` type we’ve defined instead of `Box<T>`. The
353353
code in Listing 15-9 won’t compile because Rust doesn’t know how to dereference
354354
`MyBox`.
355355
-->
356-
<p>試しにリスト15-7の<code>main</code>関数をリスト15-8に追加し、<code>Box&lt;T&gt;</code>の代わりに定義した<code>MyBox&lt;T&gt;</code>型を使うよう変更してみてください
356+
<p>試しにリスト15-7の<code>main</code>関数をリスト15-8に追加し、定義した<code>MyBox&lt;T&gt;</code>型を<code>Box&lt;T&gt;</code>の代わりに使うよう変更してみてください
357357
コンパイラは<code>MyBox</code>を参照外しする方法がわからないので、リスト15-9のコードはコンパイルできません。</p>
358358
<!--
359359
<span class="filename">Filename: src/main.rs</span>
@@ -375,7 +375,7 @@ <h3><a class="header" href="#独自のスマートポインタを定義する" i
375375
<!--
376376
Here’s the resulting compilation error:
377377
-->
378-
<p>こちらが結果として出るコンパイルエラーです:</p>
378+
<p>こちらが結果として出るコンパイルエラーです</p>
379379
<pre><code class="language-text">error[E0614]: type `MyBox&lt;{integer}&gt;` cannot be dereferenced
380380
(エラー: 型`MyBox&lt;{integer}&gt;`は参照外しできません)
381381
--&gt; src/main.rs:14:19
@@ -388,7 +388,7 @@ <h3><a class="header" href="#独自のスマートポインタを定義する" i
388388
ability on our type. To enable dereferencing with the `*` operator, we
389389
implement the `Deref` trait.
390390
-->
391-
<p><code>MyBox&lt;T&gt;</code>に参照外しの能力を実装していないので、参照外しできません<code>*</code>演算子で参照外しできるようにするには、
391+
<p><code>MyBox&lt;T&gt;</code>の参照を外すことはできません。そのための実装を与えていないからです<code>*</code>演算子で参照外しできるようにするには、
392392
<code>Deref</code>トレイトを実装します。</p>
393393
<!--
394394
### Treating a Type Like a Reference by Implementing the `Deref` Trait
@@ -401,10 +401,10 @@ <h3><a class="header" href="#derefトレイトを実装して型を参照のよ
401401
borrows `self` and returns a reference to the inner data. Listing 15-10
402402
contains an implementation of `Deref` to add to the definition of `MyBox`:
403403
-->
404-
<p>第10章で議論したように、トレイトを実装するには、トレイトの必須メソッドに実装を提供する必要があります
405-
<code>Deref</code>トレイトは標準ライブラリで提供されていますが、<code>self</code>を借用し、
406-
内部のデータへの参照を返す<code>deref</code>という1つのメソッドを実装する必要があります。リスト15-10には、
407-
<code>MyBox</code>の定義に追記する<code>Deref</code>の実装が含まれています:</p>
404+
<p>第10章で議論したように、トレイトを実装するにはトレイトの必須メソッドに実装を与える必要があります
405+
<code>Deref</code>トレイトは標準ライブラリで提供されており、<code>deref</code>という1つのメソッドの実装を要求します。<code>deref</code><code>self</code>を借用し、
406+
内部のデータへの参照を返すメソッドです。
407+
リスト15-10には、<code>MyBox</code>の定義に付け足す<code>Deref</code>の実装が含まれています</p>
408408
<!--
409409
<span class="filename">Filename: src/main.rs</span>
410410
-->
@@ -434,44 +434,40 @@ <h3><a class="header" href="#derefトレイトを実装して型を参照のよ
434434
parameter, but you don’t need to worry about them for now; we’ll cover them in
435435
more detail in Chapter 19.
436436
-->
437-
<p><code>type Target = T;</code>という記法は、<code>Deref</code>トレイトが使用する関連型を定義しています。関連型は、
438-
ジェネリック引数を宣言する少しだけ異なる方法ですが、今は気にする必要はありません; 第19章でより詳しく講義します。</p>
437+
<p><code>type Target = T;</code>という記法は、<code>Deref</code>トレイトが使用する関連型を定義しています。関連型はまた少し違ったやり方でジェネリック引数を宣言するためのものですが、今は気にする必要はありません。第19章でより詳しく扱います。</p>
439438
<!--
440439
We fill in the body of the `deref` method with `&self.0` so `deref` returns a
441440
reference to the value we want to access with the `*` operator. The `main`
442441
function in Listing 15-9 that calls `*` on the `MyBox<T>` value now compiles,
443442
and the assertions pass!
444443
-->
445-
<p><code>deref</code>メソッドの本体を<code>&amp;self.0</code>で埋めているので<code>deref</code><code>*</code>演算子でアクセスしたい値への参照を返します
444+
<p><code>deref</code>メソッドの本体は<code>&amp;self.0</code>だけなので<code>deref</code>が返すのは私達が<code>*</code>演算子でアクセスしたい値への参照なわけです
446445
リスト15-9の<code>MyBox&lt;T&gt;</code><code>*</code>を呼び出す<code>main</code>関数はこれでコンパイルでき、アサートも通ります!</p>
447446
<!--
448447
Without the `Deref` trait, the compiler can only dereference `&` references.
449448
The `deref` method gives the compiler the ability to take a value of any type
450449
that implements `Deref` and call the `deref` method to get a `&` reference that
451450
it knows how to dereference.
452451
-->
453-
<p><code>Deref</code>がなければ、コンパイラは<code>&amp;</code>参照しか参照外しできなくなります。<code>deref</code>メソッドによりコンパイラは、
454-
<code>Deref</code>を実装するあらゆる型の値を取り<code>deref</code>メソッドを呼び出して参照外しの仕方を知っている<code>&amp;</code>参照を得る能力を獲得するのです</p>
452+
<p><code>Deref</code>トレイトがないと、コンパイラは<code>&amp;</code>参照しか参照外しできません。
453+
<code>deref</code>メソッドのおかげで、コンパイラは<code>Deref</code>を実装している型の値を取り<code>deref</code>メソッドを呼ぶことで、参照外しが可能な<code>&amp;</code>参照を得られるようになります</p>
455454
<!--
456455
When we entered `*y` in Listing 15-9, behind the scenes Rust actually ran this
457456
code:
458457
-->
459-
<p>リスト15-9に<code>*y</code>を入力した時、水面下でコンパイラは、実際にはこのようなコードを走らせていました:</p>
458+
<p>リスト15-9に<code>*y</code>を入力した時、水面下でRustは実際にはこのようなコードを走らせていました。</p>
460459
<pre><code class="language-rust ignore">*(y.deref())
461460
</code></pre>
462461
<!--
463-
最後の行は、これで合っているのか自信がない・・・
464-
-->
465-
<!--
466462
Rust substitutes the `*` operator with a call to the `deref` method and then a
467463
plain dereference so we don’t have to think about whether or not we need to
468464
call the `deref` method. This Rust feature lets us write code that functions
469465
identically whether we have a regular reference or a type that implements
470466
`Deref`.
471467
-->
472-
<p>コンパイラは、<code>*</code>演算子を<code>deref</code>メソッド、それから何の変哲もない参照外しの呼び出しに置き換えるので
473-
<code>deref</code>メソッドを呼び出す必要があるかどうかを考える必要はないわけです。このRustの機能により、
474-
普通の参照か<code>Deref</code>を実装した型であるかどうかに関わらず、等しく機能するコードを書かせてくれます</p>
468+
<p>Rustが<code>*</code>演算子を<code>deref</code>メソッドの呼び出しと普通の参照外しへと置き換えてくれるので
469+
私達は<code>deref</code>メソッドを呼び出す必要があるかどうかを考えなくて済むわけです。このRustの機能により、
470+
普通の参照か<code>Deref</code>を実装した型であるかどうかに関わらず、等しく機能するコードを書くことができます</p>
475471
<!--
476472
The reason the `deref` method returns a reference to a value and that the plain
477473
dereference outside the parentheses in `*(y.deref())` is still necessary is the
@@ -480,21 +476,18 @@ <h3><a class="header" href="#derefトレイトを実装して型を参照のよ
480476
to take ownership of the inner value inside `MyBox<T>` in this case or in most
481477
cases where we use the dereference operator.
482478
-->
483-
<p><code>deref</code>メソッドが値への参照を返し、<code>*(y.deref())</code>のかっこの外の何の変哲もない参照外しがそれでも必要な理由は、
484-
所有権システムです。<code>deref</code>メソッドが値への参照ではなく、値を直接返したら、値は<code>self</code>から外にムーブされてしまいます。
485-
今回の場合や、参照外し演算子を使用する多くの場合には<code>MyBox&lt;T&gt;</code>の中の値の所有権を奪いたくはありません。</p>
486-
<!--
487-
2行目、... just once, [each time ...]という構造と思われる
488-
-->
479+
<p><code>deref</code>メソッドが値への参照を返し、<code>*(y.deref())</code>のかっこの外にある普通の参照外しがそれでも必要になるのは、
480+
所有権システムがあるからです。<code>deref</code>メソッドが値への参照ではなく値を直接返したら、値は<code>self</code>から外にムーブされてしまいます。
481+
今回もそうですが、参照外し演算子を使用するときはほとんどの場合、<code>MyBox&lt;T&gt;</code>の中の値の所有権を奪いたくはありません。</p>
489482
<!--
490483
Note that the `*` operator is replaced with a call to the `deref` method and
491484
then a call to `*` operator just once, each time we type a `*` in our code.
492485
Because the substitution of the `*` operator does not recurse infinitely, we
493486
end up with data of type `i32`, which matches the `5` in `assert_eq!` in
494487
Listing 15-9.
495488
-->
496-
<p><code>*</code>演算子は、コードで<code>*</code>を打つたびに、ただ1回、<code>deref</code>メソッドの呼び出し、そして<code>*</code>演算子の呼び出しに置き換えられることに注意してください
497-
<code>*</code>演算子の置き換えは、無限に繰り返されないので、<code>i32</code>に行き着き、リスト15-9で<code>assert_eq!</code><code>5</code>と合致します。</p>
489+
<p><code>*</code>演算子が<code>deref</code>メソッドの呼び出しと<code>*</code>演算子の呼び出しに置き換えられるのは、コード内で<code>*</code>を打つ毎にただ1回だけ、という点に注意して下さい
490+
<code>*</code>演算子の置き換えは無限に繰り返されないので、<code>i32</code>のデータに行き着きます。これはリスト15-9で<code>assert_eq!</code><code>5</code>と合致します。</p>
498491
<!--
499492
### Implicit Deref Coercions with Functions and Methods
500493
-->

0 commit comments

Comments
 (0)