Skip to content

Commit 8a44126

Browse files
committed
付録C: 導出可能なトレイトの和訳をアップデート
rust-lang/book@19c40bf
1 parent 07bc7e9 commit 8a44126

File tree

1 file changed

+57
-33
lines changed

1 file changed

+57
-33
lines changed

src/appendix-03-derivable-traits.md

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ library that you can use with `derive`. Each section covers:
3636
* そのトレイトが必要になる処理の例
3737

3838
<!--
39-
If you want different behavior than that provided by the `derive` attribute,
40-
consult the standard library documentation for each trait for details on how to
41-
manually implement them.
39+
If you want different behavior from that provided by the `derive` attribute,
40+
consult the [standard library documentation](../std/index.html)
41+
for each trait for details of how to manually implement them.
4242
-->
4343

44-
`derive`属性が提供する以外の異なる振る舞いが欲しいなら、それらを手動で実装する方法の詳細について、
45-
各トレイトの標準ライブラリのドキュメンテーションを調べてください
44+
`derive`属性が提供するものと異なる振る舞いが欲しいなら、それらを手動で実装する方法の詳細について、
45+
各トレイトの[標準ライブラリのドキュメンテーション](https://doc.rust-lang.org/std/index.html)を調べてください
4646

4747
<!--
48-
The rest of the traits defined in the standard library can’t be implemented on
49-
your types using `derive`. These traits don’t have sensible default behavior,
50-
so it’s up to you to implement them in the way that makes sense for what you’re
51-
trying to accomplish.
48+
These traits listed here are the only ones defined by the standard library that
49+
can be implemented on your types using `derive`. Other traits defined in the
50+
standard library don’t have sensible default behavior, so it’s up to you to
51+
implement them in the way that makes sense for what you’re trying to accomplish.
5252
-->
5353

54-
標準ライブラリで定義されている残りのトレイトは、`derive`で自分の型に実装することはできません
55-
これらのトレイトには知覚できるほどの既定の振る舞いはないので、自分が達成しようしていることに対して
56-
道理が通る方法でそれらを実装するのはあなた次第です。
54+
ここで列挙したトレイトは、標準ライブラリによって`derive`で自分の型に対して実装できると定義されているもののみです
55+
他の標準ライブラリで定義されているトレイトには、分別のあるデフォルトの振る舞いはないので
56+
自分が達成しようしていることに対して、道理が通る方法でそれらを実装するのはあなた次第です。
5757

5858
<!--
5959
An example of a trait that can’t be derived is `Display`, which handles
@@ -73,12 +73,13 @@ it can’t provide appropriate default behavior for you.
7373
The list of derivable traits provided in this appendix is not comprehensive:
7474
libraries can implement `derive` for their own traits, making the list of
7575
traits you can use `derive` with truly open-ended. Implementing `derive`
76-
involves using a procedural macro, which is covered in Appendix D.
76+
involves using a procedural macro, which is covered in the
77+
[“Macros”][macros] section of Chapter 19.
7778
-->
7879

7980
この付録で提供される導出可能なトレイトのリストは、包括的ではありません: ライブラリは、自身のトレイトに`derive`を実装でき、
8081
`derive`と共に使用できるトレイトのリストが実に限りのないものになってしまうのです。`derive`の実装には、
81-
プロシージャルなマクロが関連します。マクロについては、付録Dで講義します
82+
プロシージャルなマクロが関連します。マクロについては、第19章の[「マクロ」][macros]で講義します
8283

8384
<!--
8485
### `Debug` for Programmer Output
@@ -210,10 +211,10 @@ enumに導出すると、enum定義で先に定義された列挙子が、後に
210211
<!--
211212
The `PartialOrd` trait is required, for example, for the `gen_range` method
212213
from the `rand` crate that generates a random value in the range specified by a
213-
low value and a high value.
214+
range expression.
214215
-->
215216

216-
`PartialOrd`トレイトが必要になる例には、低い値と高い値で指定される範囲の乱数を生成する`rand`クレートの`gen_range`メソッドが挙げられます。
217+
`PartialOrd`トレイトが必要になる例には、範囲式で指定される範囲の乱数を生成する`rand`クレートの`gen_range`メソッドが挙げられます。
217218

218219
<!--
219220
The `Ord` trait allows you to know that for any two values of the annotated
@@ -248,13 +249,14 @@ a data structure that stores data based on the sort order of the values.
248249
<!--
249250
The `Clone` trait allows you to explicitly create a deep copy of a value, and
250251
the duplication process might involve running arbitrary code and copying heap
251-
data. See the “Ways Variables and Data Interact: Clone” section in Chapter 4
252-
for more information on `Clone`.
252+
data. See the [“Ways Variables and Data Interact:
253+
Clone”][ways-variables-and-data-interact-clone] section in
254+
Chapter 4 for more information on `Clone`.
253255
-->
254256

255257
`Clone`トレイトにより値のディープコピーを明示的に行うことができ、複製のプロセスは、任意のコードを実行し、
256258
ヒープデータをコピーすることに関係がある可能性があります。`Clone`について詳しくは、
257-
第4章の「変数とデータの相互作用法: Clone」節を参照されたし。
259+
第4章の[「変数とデータの相互作用法: Clone」][ways-variables-and-data-interact-clone]節を参照されたし。
258260

259261
<!--
260262
Deriving `Clone` implements the `clone` method, which when implemented for the
@@ -279,12 +281,13 @@ returned from `to_vec` will need to own its instances, so `to_vec` calls
279281

280282
<!--
281283
The `Copy` trait allows you to duplicate a value by only copying bits stored on
282-
the stack; no arbitrary code is necessary. See the “Stack-Only Data: Copy”
283-
section in Chapter 4 for more information on `Copy`.
284+
the stack; no arbitrary code is necessary. See the [“Stack-Only Data:
285+
Copy”][stack-only-data-copy] section in Chapter 4 for more
286+
information on `Copy`.
284287
-->
285288

286289
`Copy`トレイトにより、スタックに格納されたビットをコピーするだけで値を複製できます; 任意のコードは必要ありません。
287-
`Copy`について詳しくは、第4章の「スタックのみのデータ: Copy」を参照されたし。
290+
`Copy`について詳しくは、第4章の[「スタックのみのデータ: Copy」][stack-only-data-copy]を参照されたし。
288291

289292
<!--
290293
The `Copy` trait doesn’t define any methods to prevent programmers from
@@ -297,14 +300,14 @@ very fast.
297300
そのため、全プログラマは、値のコピーは非常に高速であることを前提にすることができます。
298301

299302
<!--
300-
You can derive `Copy` on any type whose parts all implement `Copy`. You can
301-
only apply the `Copy` trait to types that also implement `Clone`, because a
302-
type that implements `Copy` has a trivial implementation of `Clone` that
303-
performs the same task as `Copy`.
303+
You can derive `Copy` on any type whose parts all implement `Copy`. A type that
304+
implements `Copy` must also implement `Clone`, because a type that implements
305+
`Copy` has a trivial implementation of `Clone` that performs the same task as
306+
`Copy`.
304307
-->
305308

306-
部品すべてが`Copy`を実装する任意の型に対して`Copy`を導出することができます。`Clone`も実装する型に対してのみ、
307-
`Copy`トレイトを適用することができます。何故なら、`Copy`を実装する型には、
309+
部品すべてが`Copy`を実装する任意の型に対して`Copy`を導出することができます。
310+
`Copy`を実装する型は、`Clone`も実装しなくてはなりません。何故なら、`Copy`を実装する型には、
308311
`Copy`と同じ作業を行う`Clone`の<ruby>瑣末<rp>(</rp><rt>さまつ</rt><rp>)</rp></ruby>な実装があるからです。
309312

310313
<!--
@@ -361,7 +364,7 @@ The `Default` trait allows you to create a default value for a type. Deriving
361364
`Default` implements the `default` function. The derived implementation of the
362365
`default` function calls the `default` function on each part of the type,
363366
meaning all fields or values in the type must also implement `Default` to
364-
derive `Default.`
367+
derive `Default`.
365368
-->
366369

367370
`Default`トレイトにより、型に対して既定値を生成できます。`Default`を導出すると、`default`関数を実装します。
@@ -370,14 +373,16 @@ derive `Default.`
370373

371374
<!--
372375
The `Default::default` function is commonly used in combination with the struct
373-
update syntax discussed in the “Creating Instances From Other Instances With
374-
Struct Update Syntax” section in Chapter 5. You can customize a few fields of a
375-
struct and then set and use a default value for the rest of the fields by using
376+
update syntax discussed in the [“Creating Instances From Other Instances With
377+
Struct Update
378+
Syntax”][creating-instances-from-other-instances-with-struct-update-syntax]
379+
section in Chapter 5. You can customize a few fields of a struct and then
380+
set and use a default value for the rest of the fields by using
376381
`..Default::default()`.
377382
-->
378383

379384
`Default::default`関数は、
380-
第5章の「構造体更新記法で他のインスタンスからインスタンスを生成する」節で議論した構造体更新記法と組み合わせてよく使用されます。
385+
第5章の[「構造体更新記法で他のインスタンスからインスタンスを生成する」][creating-instances-from-other-instances-with-struct-update-syntax]節で議論した構造体更新記法と組み合わせてよく使用されます。
381386
構造体のいくつかのフィールドをカスタマイズし、それから`..Default::default()`を使用して、
382387
残りのフィールドに対して既定値をセットし使用することができます。
383388

@@ -390,3 +395,22 @@ The `Default` trait is required when you use the method `unwrap_or_default` on
390395

391396
例えば、`Default`トレイトは、`Option<T>`インスタンスに対してメソッド`unwrap_or_default`を使用する時に必要になります。
392397
`Option<T>``None`ならば、メソッド`unwrap_or_default`は、`Option<T>`に格納された型`T`に対して`Default::default`の結果を返します。
398+
399+
<!--
400+
[creating-instances-from-other-instances-with-struct-update-syntax]:
401+
ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
402+
[stack-only-data-copy]:
403+
ch04-01-what-is-ownership.html#stack-only-data-copy
404+
[ways-variables-and-data-interact-clone]:
405+
ch04-01-what-is-ownership.html#ways-variables-and-data-interact-clone
406+
[macros]: ch19-06-macros.html#macros
407+
-->
408+
409+
[creating-instances-from-other-instances-with-struct-update-syntax]:
410+
ch05-01-defining-structs.html#構造体更新記法で他のインスタンスからインスタンスを生成する
411+
[stack-only-data-copy]:
412+
ch04-01-what-is-ownership.html#スタックのみのデータ-コピー
413+
[ways-variables-and-data-interact-clone]:
414+
ch04-01-what-is-ownership.html#クローンによる変数とデータの相互作用
415+
[macros]: ch19-06-macros.html#マクロ
416+

0 commit comments

Comments
 (0)