Skip to content

Commit f22e96c

Browse files
committed
Update Associated Types to 1.9
1 parent 2dad777 commit f22e96c

File tree

2 files changed

+16
-49
lines changed

2 files changed

+16
-49
lines changed

1.9/ja/book/associated-types.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn distance<N, E, G: Graph<N, E>>(graph: &G, start: &N, end: &N) -> u32 { ... }
3232
```
3333

3434
<!-- Our distance calculation works regardless of our `Edge` type, so the `E` stuff in -->
35-
<!-- this signature is just a distraction. -->
36-
この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる `E` に関連する部分は邪魔でしかありません
35+
<!-- this signature is a distraction. -->
36+
この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる `E` に関連する部分は邪魔となります
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: -->
@@ -52,7 +52,7 @@ 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 { ... }
@@ -61,7 +61,6 @@ fn distance<G: Graph>(graph: &G, start: &G::N, end: &G::N) -> u32 { ... }
6161
<!-- No need to deal with the `E`dge type here! -->
6262
もう `E` について扱う必要はありません!
6363

64-
6564
<!-- Let’s go over all this in more detail. -->
6665
もっと詳しく見ていきましょう。
6766

@@ -89,7 +88,7 @@ trait Graph {
8988
<!-- if we wanted our `N` type to implement `Display`, so we can print the nodes out, -->
9089
<!-- we could do this: -->
9190
これらの `type` 宣言は、関数で利用できるものと同じものが全て利用できます。
92-
たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定することができます:
91+
たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定できます:
9392

9493
```rust
9594
use std::fmt;
@@ -141,14 +140,14 @@ impl Graph for MyGraph {
141140
<!-- This silly implementation always returns `true` and an empty `Vec<Edge>`, but it -->
142141
<!-- gives you an idea of how to implement this kind of thing. We first need three -->
143142
<!-- `struct`s, one for the graph, one for the node, and one for the edge. If it made -->
144-
<!-- more sense to use a different type, that would work as well, we’re just going to -->
143+
<!-- more sense to use a different type, that would work as well, we’re going to -->
145144
<!-- use `struct`s for all three here. -->
146-
この奇妙な実装は、つねに `true` と空の `Vec<Edge>` を返しますが、どのように定義したら良いかのアイデアをくれます。
145+
この奇妙な実装は、常に `true` と空の `Vec<Edge>` を返しますが、どのように定義したら良いかのアイデアをくれます。
147146
まず、はじめに3つの `struct` が必要です、ひとつはグラフのため、そしてひとつは頂点のため、そしてもうひとつは辺のため。
148-
もし異なる型を利用することが適切ならば、そのようにすると良いでしょう、今回はこの3つの `struct` を用います
149-
147+
もし異なる型を利用することが適切ならば、そのようにすると良いでしょう。
148+
今回はこの3つの `struct` を用います。
150149

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

154153
<!-- From here, we use `=` to define our associated types. The name the trait uses -->
@@ -163,9 +162,9 @@ impl Graph for MyGraph {
163162
## 関連型を伴うトレイト
164163

165164
<!-- There’s one more bit of syntax we should talk about: trait objects. If you -->
166-
<!-- try to create a trait object from an associated type, like this: -->
167-
すこし触れておきたい構文: トレイトオブジェクト が有ります
168-
もし、トレイトオブジェクトを以下のように関連型から作成しようとした場合:
165+
<!-- try to create a trait object from a trait with an associated type, like this: -->
166+
すこし触れておきたい構文: トレイトオブジェクト があります
167+
もし、トレイトオブジェクトを以下のように関連型を持つトレイトから作成しようとした場合:
169168

170169
```rust,ignore
171170
# trait Graph {
@@ -207,7 +206,8 @@ let obj = Box::new(graph) as Box<Graph>;
207206

208207
<!-- We can’t create a trait object like this, because we don’t know the associated -->
209208
<!-- types. Instead, we can write this: -->
210-
上のようにしてトレイトオブジェクトを作ることはできません、なぜなら関連型について知らないからです
209+
上のようにしてトレイトオブジェクトを作ることはできません。
210+
なぜなら関連型について知らないからです。
211211
代わりに以下のように書くことができます:
212212

213213
```rust
@@ -237,5 +237,6 @@ let obj = Box::new(graph) as Box<Graph<N=Node, E=Edge>>;
237237
<!-- The `N=Node` syntax allows us to provide a concrete type, `Node`, for the `N` -->
238238
<!-- type parameter. Same with `E=Edge`. If we didn’t provide this constraint, we -->
239239
<!-- couldn’t be sure which `impl` to match this trait object to. -->
240-
`N=Node` 構文を用いて型パラメータ `N` にたいして具体的な型 `Node` を指定することができます、`E=Edge` についても同様です。
240+
`N=Node` 構文を用いて型パラメータ `N` に対して具体的な型 `Node` を指定できます。
241+
`E=Edge` についても同様です。
241242
もしこの制約を指定しなかった場合、このトレイトオブジェクトに対してどの `impl` がマッチするのか定まりません。

diff-1.6.0..1.9.0/src/doc/book/associated-types.md

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)