7
7
<!-- to write a `Graph` trait, you have two types to be generic over: the node type -->
8
8
<!-- and the edge type. So you might write a trait, `Graph<N, E>`, that looks like -->
9
9
<!-- this: -->
10
- 関連型は、Rust型システムの強力な部分です。関連型は、「型族」という概念と関連が有り、
11
- 言い換えると、複数の型をグループ化するものです。
10
+ 関連型は、Rust型システムの強力な部分です。
11
+ 関連型は、「型族」という概念と関連があり、 言い換えると、複数の型をグループ化するものです。
12
12
この説明はすこし抽象的なので、実際の例を見ていきましょう。
13
13
例えば、 ` Graph ` トレイトを定義したいとしましょう、このときジェネリックになる2つの型: 頂点の型、辺の型 が存在します。
14
14
そのため、以下のように ` Graph<N, E> ` と書きたくなるでしょう:
@@ -33,12 +33,12 @@ fn distance<N, E, G: Graph<N, E>>(graph: &G, start: &N, end: &N) -> u32 { ... }
33
33
34
34
<!-- Our distance calculation works regardless of our `Edge` type, so the `E` stuff in -->
35
35
<!-- this signature is a distraction. -->
36
- この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる ` E ` に関連する部分は邪魔となります 。
36
+ この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる ` E ` に関連する部分は邪魔になります 。
37
37
38
38
<!-- What we really want to say is that a certain `E`dge and `N`ode type come together -->
39
39
<!-- to form each kind of `Graph`. We can do that with associated types: -->
40
40
本当に表現したいことは、それぞれのグラフ( ` Graph ` )は辺( ` E ` )や頂点( ` N ` )で構成されているということです。
41
- それは、以下のように関連型を用いて表現することができます :
41
+ それは、以下のように関連型を用いて表現できます :
42
42
43
43
``` rust
44
44
trait Graph {
@@ -59,7 +59,7 @@ fn distance<G: Graph>(graph: &G, start: &G::N, end: &G::N) -> u32 { ... }
59
59
```
60
60
61
61
<!-- No need to deal with the `E`dge type here! -->
62
- もう ` E ` について扱う必要はありません!
62
+ もう ` E ` について扱う必要はありません!
63
63
64
64
<!-- Let’s go over all this in more detail. -->
65
65
もっと詳しく見ていきましょう。
@@ -163,7 +163,7 @@ impl Graph for MyGraph {
163
163
164
164
<!-- There’s one more bit of syntax we should talk about: trait objects. If you -->
165
165
<!-- try to create a trait object from a trait with an associated type, like this: -->
166
- すこし触れておきたい構文: トレイトオブジェクト があります 。
166
+ すこし触れておきたい構文のひとつに、トレイトオブジェクトがあります 。
167
167
もし、トレイトオブジェクトを以下のように関連型を持つトレイトから作成しようとした場合:
168
168
169
169
``` rust,ignore
0 commit comments