Skip to content

Commit 2ddd2ca

Browse files
committed
Brush up the translation of Associated Types (1.9)
1 parent 1317d15 commit 2ddd2ca

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

1.9/ja/book/associated-types.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait Graph<N, E> {
2525
<!-- that wants to take a `Graph` as a parameter now _also_ needs to be generic over -->
2626
<!-- the `N`ode and `E`dge types too: -->
2727
たしかに上のようなコードは動作しますが、この `Graph` の定義は少し扱いづらいです。
28-
たとえば、任意の `Graph` を引数に取る関数は、 _同時に_ 頂点 `N` と辺 `E` についてもジェネリックとなることになります:
28+
たとえば、任意の `Graph` を引数に取る関数は、 _さらに_ 頂点 `N` と辺 `E` の型についてもジェネリックになる必要があります:
2929

3030
```rust,ignore
3131
fn distance<N, E, G: Graph<N, E>>(graph: &G, start: &N, end: &N) -> u32 { ... }
@@ -37,7 +37,7 @@ fn distance<N, E, G: Graph<N, E>>(graph: &G, start: &N, end: &N) -> u32 { ... }
3737

3838
<!-- What we really want to say is that a certain `E`dge and `N`ode type come together -->
3939
<!-- to form each kind of `Graph`. We can do that with associated types: -->
40-
本当に表現したいことは、それぞれのグラフ( `Graph` )は辺( `E` )や頂点( `N` )で構成されているということです
40+
本当に表現したいのは、それぞれの `Graph` は、辺 `E` と頂点 `N` で構成されていることです
4141
それは、以下のように関連型を用いて表現できます:
4242

4343
```rust
@@ -52,14 +52,14 @@ trait Graph {
5252
```
5353

5454
<!-- Now, our clients can be abstract over a given `Graph`: -->
55-
このようにすると、`Graph` を使った関数は以下のように書けます:
55+
こうすると、利用者側では、個々の `Graph` をより抽象的なものとして扱えます:
5656

5757
```rust,ignore
5858
fn distance<G: Graph>(graph: &G, start: &G::N, end: &G::N) -> u32 { ... }
5959
```
6060

6161
<!-- No need to deal with the `E`dge type here! -->
62-
もう `E` について扱う必要はありません
62+
ここでは、頂点 `E` 型を扱わずに済んでいます
6363

6464
<!-- Let’s go over all this in more detail. -->
6565
もっと詳しく見ていきましょう。
@@ -82,13 +82,13 @@ trait Graph {
8282

8383
<!-- Simple enough. Associated types use the `type` keyword, and go inside the body -->
8484
<!-- of the trait, with the functions. -->
85-
非常にシンプルですね。関連型には `type` キーワードを使い、そしてトレイトの本体や関数で利用します
85+
非常にシンプルですね。関連型には `type` キーワードを使い、そしてトレイトの本体にある関数で利用します
8686

8787
<!-- These `type` declarations can have all the same thing as functions do. For example, -->
8888
<!-- if we wanted our `N` type to implement `Display`, so we can print the nodes out, -->
8989
<!-- we could do this: -->
9090
これらの `type` 宣言は、関数で利用できるものと同じものが全て利用できます。
91-
たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定できます:
91+
たとえば、頂点を表示するために、`N` 型に `Display` を実装してほしい場合は、以下のように指定できます:
9292

9393
```rust
9494
use std::fmt;
@@ -142,13 +142,15 @@ impl Graph for MyGraph {
142142
<!-- `struct`s, one for the graph, one for the node, and one for the edge. If it made -->
143143
<!-- more sense to use a different type, that would work as well, we’re going to -->
144144
<!-- use `struct`s for all three here. -->
145-
この奇妙な実装は、常に `true` と空の `Vec<Edge>` を返しますが、どのように定義したら良いかのアイデアをくれます。
146-
まず、はじめに3つの `struct` が必要です、ひとつはグラフのため、そしてひとつは頂点のため、そしてもうひとつは辺のため。
147-
もし異なる型を利用することが適切ならば、そのようにすると良いでしょう。
145+
この少し単純すぎる実装は、常に `true` と空の `Vec<Edge>` を返しますが、どのように定義したら良いかのアイデアをくれます。
146+
まず、はじめに3つの `struct` が必要です。
147+
グラフのためにひとつ、頂点のためにひとつ、辺のためにひとつです。
148+
もし異なる型を利用するのが適切ならば、そうしても構いません。
148149
今回はこの3つの `struct` を用います。
149150

150151
<!-- Next is the `impl` line, which is an implementing like any other trait. -->
151-
次は `impl` の行です、これは他のトレイトを実装するときと同様です。
152+
次は `impl` の行です。
153+
これは他のトレイトを実装するときと同様です。
152154

153155
<!-- From here, we use `=` to define our associated types. The name the trait uses -->
154156
<!-- goes on the left of the `=`, and the concrete type we’re `impl`ementing this -->
@@ -208,7 +210,7 @@ let obj = Box::new(graph) as Box<Graph>;
208210
<!-- types. Instead, we can write this: -->
209211
上のようにしてトレイトオブジェクトを作ることはできません。
210212
なぜなら関連型について知らないからです。
211-
代わりに以下のように書くことができます:
213+
代わりに以下のように書けます:
212214

213215
```rust
214216
# trait Graph {

0 commit comments

Comments
 (0)