From dfd7defb84ef8c381c66f8517f72a8434ea77fa9 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Sun, 7 Feb 2016 00:02:13 +0900 Subject: [PATCH 1/5] Start translation. --- 1.6/ja/book/associated-types.md | 77 +++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/1.6/ja/book/associated-types.md b/1.6/ja/book/associated-types.md index fe4f27b9..aa63d709 100644 --- a/1.6/ja/book/associated-types.md +++ b/1.6/ja/book/associated-types.md @@ -1,11 +1,16 @@ -% Associated Types - -Associated types are a powerful part of Rust’s type system. They’re related to -the idea of a ‘type family’, in other words, grouping multiple types together. That -description is a bit abstract, so let’s dive right into an example. If you want -to write a `Graph` trait, you have two types to be generic over: the node type -and the edge type. So you might write a trait, `Graph`, that looks like -this: +% 関連型 + + + + + + + + +関連型は、Rust型システムの強力な部分です。関連型は、「タイプファミリー」というアイデアと関連が有ります、 +言い換えると、複数の方をグルーピングするものです。この説明はすこし抽象的なので、実際の例を見ていきましょう。 +例えば、 `Graph` トレイトを定義したいとしましょう、このとき `Graph` トレイトは頂点の方と、辺の型についてジェネリックとなることになります。 +なので、以下のように`Graph` と書きたくなるでしょう: ```rust trait Graph { @@ -15,19 +20,24 @@ trait Graph { } ``` -While this sort of works, it ends up being awkward. For example, any function -that wants to take a `Graph` as a parameter now _also_ needs to be generic over -the `N`ode and `E`dge types too: + + + +たしかに、上のようなコードは動作します、しかしこのような `Graph` の定義は少し扱いづらいです。 +たとえば、任意の `Graph` を引数に取る関数は、 _同時に_ `N` と `E` についてもジェネリックとなることになります: ```rust,ignore fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } ``` -Our distance calculation works regardless of our `Edge` type, so the `E` stuff in -this signature is just a distraction. + + +上のような距離を計算するdistance関数は、辺の型に関係がありません、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 -What we really want to say is that a certain `E`dge and `N`ode type come together -to form each kind of `Graph`. We can do that with associated types: + + +本当に表現したいことは、辺の型 `E` や頂点の型 `N` がそれぞれの `Graph` について決まっているということです。 +それは、以下のように関連型を用いて表現することができます: ```rust trait Graph { @@ -40,19 +50,25 @@ trait Graph { } ``` -Now, our clients can be abstract over a given `Graph`: + +このようにすると、`Graph` を使った関数は以下のように書くことができます: ```rust,ignore fn distance(graph: &G, start: &G::N, end: &G::N) -> u32 { ... } ``` -No need to deal with the `E`dge type here! + +もう `E` について扱う必要はありません! + -Let’s go over all this in more detail. + +もっと詳しく見ていきましょう。 -## Defining associated types + +## 関連型を定義する -Let’s build that `Graph` trait. Here’s the definition: + +早速、`Graph` トレイトを定義しましょう。以下がその定義です: ```rust trait Graph { @@ -64,12 +80,15 @@ trait Graph { } ``` -Simple enough. Associated types use the `type` keyword, and go inside the body -of the trait, with the functions. + + +十分にシンプルです。関連型を定義するには `type` キーワードを使います、そしてトレイトの本体や関数で利用します。 -These `type` declarations can have all the same thing as functions do. For example, -if we wanted our `N` type to implement `Display`, so we can print the nodes out, -we could do this: + + + +これらの `type` 宣言は、関数におけるものと同じ物を指定することができます。 +たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定することができます: ```rust use std::fmt; @@ -83,10 +102,12 @@ trait Graph { } ``` -## Implementing associated types + +## 関連型を実装する -Just like any trait, traits that use associated types use the `impl` keyword to -provide implementations. Here’s a simple implementation of Graph: + + +通常のトレイトと同様に、関連型を使っているトレイト ```rust # trait Graph { From 637fc803bcb5a599624bdf5a02202880c08d06d0 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Mon, 8 Feb 2016 14:08:06 +0900 Subject: [PATCH 2/5] Roughly translated. --- 1.6/ja/book/associated-types.md | 71 +++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/1.6/ja/book/associated-types.md b/1.6/ja/book/associated-types.md index aa63d709..204d4be2 100644 --- a/1.6/ja/book/associated-types.md +++ b/1.6/ja/book/associated-types.md @@ -7,9 +7,10 @@ -関連型は、Rust型システムの強力な部分です。関連型は、「タイプファミリー」というアイデアと関連が有ります、 -言い換えると、複数の方をグルーピングするものです。この説明はすこし抽象的なので、実際の例を見ていきましょう。 -例えば、 `Graph` トレイトを定義したいとしましょう、このとき `Graph` トレイトは頂点の方と、辺の型についてジェネリックとなることになります。 +関連型は、Rust型システムの強力な部分です。関連型は、「タイプファミリー」というアイデアと関連が有り、 +言い換えると、複数の方をグルーピングするものです。 +この説明はすこし抽象的なので、実際の例を見ていきましょう。 +例えば、 `Graph` トレイトを定義したいとしましょう、このとき `Graph` トレイトは頂点の型と、辺の型についてジェネリックとなることになります。 なので、以下のように`Graph` と書きたくなるでしょう: ```rust @@ -32,7 +33,7 @@ fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } -上のような距離を計算するdistance関数は、辺の型に関係がありません、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 +上のような距離を計算するdistance関数は、辺の型に関わらず動作します、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 @@ -82,12 +83,12 @@ trait Graph { -十分にシンプルです。関連型を定義するには `type` キーワードを使います、そしてトレイトの本体や関数で利用します。 +非常にシンプルですね。関連型を定義するには `type` キーワードを使います、そしてトレイトの本体や関数で利用します。 -これらの `type` 宣言は、関数におけるものと同じ物を指定することができます。 +これらの `type` 宣言は、関数におけるものと同じ物をすべて持っています。 たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定することができます: ```rust @@ -107,7 +108,8 @@ trait Graph { -通常のトレイトと同様に、関連型を使っているトレイト +通常のトレイトと同様に、関連型を使っているトレイトは実装するために `impl` を利用します。 +以下は、シンプルなGraphの実装例です: ```rust # trait Graph { @@ -136,23 +138,35 @@ impl Graph for MyGraph { } ``` -This silly implementation always returns `true` and an empty `Vec`, but it -gives you an idea of how to implement this kind of thing. We first need three -`struct`s, one for the graph, one for the node, and one for the edge. If it made -more sense to use a different type, that would work as well, we’re just going to -use `struct`s for all three here. + + + + + +この奇妙な実装は、つねに `true` と空の `Vec` を返します、 +しかし、上のコードはどのように定義したら良いかのアイデアをくれます。 +まず、はじめに3つの `struct` が必要です、ひとつはグラフのため、そしてひとつは頂点のため、そしてもうひとつは辺のため。 +もし異なる型を利用することが適切ならば、そのようにすると良いでしょう、今回はこの3つの `struct` を用います。 -Next is the `impl` line, which is just like implementing any other trait. -From here, we use `=` to define our associated types. The name the trait uses -goes on the left of the `=`, and the concrete type we’re `impl`ementing this -for goes on the right. Finally, we use the concrete types in our function -declarations. + +次に、 `impl` の行です、これは他のトレイトを実装するとき同様です。 -## Trait objects with associated types + + + + +ここからは、`=` を関連型を定義するために利用します。 +トレイトが利用名前はするのは、 `=` の左側にある名前で、実装に用いる具体的な型は右側にあるものになります。 +最後に、具体的な型を関数の宣言に利用します。 -There’s one more bit of syntax we should talk about: trait objects. If you -try to create a trait object from an associated type, like this: + +## 関連型を伴うトレイト + + + +すこし触れておきたい構文: トレイトオブジェクト が有ります。 +もし、トレイトオブジェクトを以下のように関連型から作成しようとした場合: ```rust,ignore # trait Graph { @@ -178,7 +192,8 @@ let graph = MyGraph; let obj = Box::new(graph) as Box; ``` -You’ll get two errors: + +以下の様なエラーが発生します: ```text error: the value of the associated type `E` (from the trait `main::Graph`) must @@ -191,8 +206,10 @@ let obj = Box::new(graph) as Box; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` -We can’t create a trait object like this, because we don’t know the associated -types. Instead, we can write this: + + +上のようにしてトレイトオブジェクトを作ることはできません、なぜなら関連型について知らないからです +代わりに以下のように書くことができます: ```rust # trait Graph { @@ -218,6 +235,8 @@ let graph = MyGraph; let obj = Box::new(graph) as Box>; ``` -The `N=Node` syntax allows us to provide a concrete type, `Node`, for the `N` -type parameter. Same with `E=Edge`. If we didn’t provide this constraint, we -couldn’t be sure which `impl` to match this trait object to. + + + +`N=Node` 構文を用いて型パラメータ `N` にたいして具体的な型 `Node` を指定することができます、`E=Edge` についても同様です。 +もしこの制約を指定しなかった場合、このトレイトオブジェクトに対してどの `impl` がマッチするのか定まりません。 From e7cd2bff872c7302ecee6e7ca4bdec5bc486281b Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Mon, 8 Feb 2016 14:30:57 +0900 Subject: [PATCH 3/5] Fix translation. --- 1.6/ja/book/associated-types.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/1.6/ja/book/associated-types.md b/1.6/ja/book/associated-types.md index 204d4be2..72d54b8f 100644 --- a/1.6/ja/book/associated-types.md +++ b/1.6/ja/book/associated-types.md @@ -8,10 +8,10 @@ 関連型は、Rust型システムの強力な部分です。関連型は、「タイプファミリー」というアイデアと関連が有り、 -言い換えると、複数の方をグルーピングするものです。 +言い換えると、複数の方をグループ化するものです。 この説明はすこし抽象的なので、実際の例を見ていきましょう。 -例えば、 `Graph` トレイトを定義したいとしましょう、このとき `Graph` トレイトは頂点の型と、辺の型についてジェネリックとなることになります。 -なので、以下のように`Graph` と書きたくなるでしょう: +例えば、 `Graph` トレイトを定義したいとしましょう、このときジェネリックになる2つの型: 頂点の型、辺の型 が存在します。 +そのため、以下のように`Graph` と書きたくなるでしょう: ```rust trait Graph { @@ -24,8 +24,8 @@ trait Graph { -たしかに、上のようなコードは動作します、しかしこのような `Graph` の定義は少し扱いづらいです。 -たとえば、任意の `Graph` を引数に取る関数は、 _同時に_ `N` と `E` についてもジェネリックとなることになります: +たしかに上のようなコードは動作しますが、この `Graph` の定義は少し扱いづらいです。 +たとえば、任意の `Graph` を引数に取る関数は、 _同時に_ 頂点 `N` と辺 `E` についてもジェネリックとなることになります: ```rust,ignore fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } @@ -33,11 +33,11 @@ fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } -上のような距離を計算するdistance関数は、辺の型に関わらず動作します、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 +この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 -本当に表現したいことは、辺の型 `E` や頂点の型 `N` がそれぞれの `Graph` について決まっているということです。 +本当に表現したいことは、辺の型 `E` や頂点の型 `N` がそれぞれの `Graph` を構成しているということです。 それは、以下のように関連型を用いて表現することができます: ```rust @@ -83,12 +83,12 @@ trait Graph { -非常にシンプルですね。関連型を定義するには `type` キーワードを使います、そしてトレイトの本体や関数で利用します。 +非常にシンプルですね。関連型には `type` キーワードを使い、そしてトレイトの本体や関数で利用します。 -これらの `type` 宣言は、関数におけるものと同じ物をすべて持っています。 +これらの `type` 宣言は、関数で利用できるものと同じものが全て利用できます。 たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定することができます: ```rust @@ -143,21 +143,20 @@ impl Graph for MyGraph { -この奇妙な実装は、つねに `true` と空の `Vec` を返します、 -しかし、上のコードはどのように定義したら良いかのアイデアをくれます。 +この奇妙な実装は、つねに `true` と空の `Vec` を返しますますが、どのように定義したら良いかのアイデアをくれます。 まず、はじめに3つの `struct` が必要です、ひとつはグラフのため、そしてひとつは頂点のため、そしてもうひとつは辺のため。 もし異なる型を利用することが適切ならば、そのようにすると良いでしょう、今回はこの3つの `struct` を用います。 -次に、 `impl` の行です、これは他のトレイトを実装するとき同様です。 +次は `impl` の行です、これは他のトレイトを実装するときと同様です。 -ここからは、`=` を関連型を定義するために利用します。 -トレイトが利用名前はするのは、 `=` の左側にある名前で、実装に用いる具体的な型は右側にあるものになります。 +そして、`=` を関連型を定義するために利用します。 +トレイトが利用する名前は `=` の左側にある名前で、実装に用いる具体的な型は右側にあるものになります。 最後に、具体的な型を関数の宣言に利用します。 From e75b1c11ad0a182a5896388fda1d4b199505ed8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=BA=80=E7=9C=9E=E6=80=9C?= Date: Tue, 9 Feb 2016 13:09:15 +0900 Subject: [PATCH 4/5] update translation --- 1.6/ja/book/associated-types.md | 8 ++++---- TranslationTable.md | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/1.6/ja/book/associated-types.md b/1.6/ja/book/associated-types.md index 72d54b8f..c588f2f6 100644 --- a/1.6/ja/book/associated-types.md +++ b/1.6/ja/book/associated-types.md @@ -7,8 +7,8 @@ -関連型は、Rust型システムの強力な部分です。関連型は、「タイプファミリー」というアイデアと関連が有り、 -言い換えると、複数の方をグループ化するものです。 +関連型は、Rust型システムの強力な部分です。関連型は、「型族」という概念と関連が有り、 +言い換えると、複数の型をグループ化するものです。 この説明はすこし抽象的なので、実際の例を見ていきましょう。 例えば、 `Graph` トレイトを定義したいとしましょう、このときジェネリックになる2つの型: 頂点の型、辺の型 が存在します。 そのため、以下のように`Graph` と書きたくなるでしょう: @@ -33,11 +33,11 @@ fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } -この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャにふくまれる `E` に関連する部分は邪魔でしかありません。 +この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる `E` に関連する部分は邪魔でしかありません。 -本当に表現したいことは、辺の型 `E` や頂点の型 `N` がそれぞれの `Graph` を構成しているということです。 +本当に表現したいことは、それぞれのグラフ(Graph)は辺(E)や頂点(N)で構成されているということです。 それは、以下のように関連型を用いて表現することができます: ```rust diff --git a/TranslationTable.md b/TranslationTable.md index 3563c844..f636cfed 100644 --- a/TranslationTable.md +++ b/TranslationTable.md @@ -99,6 +99,7 @@ | tick | クオート | trait | トレイト | type inference | 型推論 +| type family | 型族 | Universal Function Call Syntax | 共通の関数呼び出し構文 | unsigned | 符号無し | unsized type | サイズ不定型 From 6de93971740f5569cef92d6e5bc2930284d761bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=BA=80=E7=9C=9E=E6=80=9C?= Date: Tue, 9 Feb 2016 14:11:45 +0900 Subject: [PATCH 5/5] fix translation --- 1.6/ja/book/associated-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1.6/ja/book/associated-types.md b/1.6/ja/book/associated-types.md index c588f2f6..03ab100d 100644 --- a/1.6/ja/book/associated-types.md +++ b/1.6/ja/book/associated-types.md @@ -11,7 +11,7 @@ 言い換えると、複数の型をグループ化するものです。 この説明はすこし抽象的なので、実際の例を見ていきましょう。 例えば、 `Graph` トレイトを定義したいとしましょう、このときジェネリックになる2つの型: 頂点の型、辺の型 が存在します。 -そのため、以下のように`Graph` と書きたくなるでしょう: +そのため、以下のように `Graph` と書きたくなるでしょう: ```rust trait Graph { @@ -37,7 +37,7 @@ fn distance>(graph: &G, start: &N, end: &N) -> u32 { ... } -本当に表現したいことは、それぞれのグラフ(Graph)は辺(E)や頂点(N)で構成されているということです。 +本当に表現したいことは、それぞれのグラフ( `Graph` )は辺( `E` )や頂点( `N` )で構成されているということです。 それは、以下のように関連型を用いて表現することができます: ```rust