From 06f088d02f50eadc9e6263a15ff4b97da45508c7 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Thu, 11 Feb 2016 18:29:27 +0900 Subject: [PATCH 1/6] Start translation. --- 1.6/ja/book/operators-and-overloading.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index e53664ee..1577aa1e 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -1,11 +1,15 @@ -% Operators and Overloading +% 演算子とオーバーロード + -Rust allows for a limited form of operator overloading. There are certain -operators that are able to be overloaded. To support a particular operator -between types, there’s a specific trait that you can implement, which then -overloads the operator. + + + + +Rustは制限された形での演算子オーバーロードを許可しており、いくつかのオーバーロード可能な演算子が存在します。 +型同士の間の演算子をサポートするための特定のトレイトが存在し、それらを実装することで演算子をオーバーロードすることができます。 -For example, the `+` operator can be overloaded with the `Add` trait: + +例えば、 `+` の演算子は `Add` トレイトを利用することでオーバーロードすることができます: ```rust use std::ops::Add; @@ -34,8 +38,8 @@ fn main() { } ``` -In `main`, we can use `+` on our two `Point`s, since we’ve implemented -`Add` for `Point`. + + There are a number of operators that can be overloaded this way, and all of their associated traits live in the [`std::ops`][stdops] module. Check out its From f9371558dfcfb4a8b790fa61e32ba712e72e4102 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Thu, 11 Feb 2016 23:10:52 +0900 Subject: [PATCH 2/6] Roughly Translated. --- 1.6/ja/book/operators-and-overloading.md | 57 ++++++++++++++++-------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index 1577aa1e..5b2b88dd 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -40,15 +40,21 @@ fn main() { +`main` 中で、2つの `Point` に対して `+` を使うことができます、 +これは `Point` にたいして `Add` を実装したためです。 -There are a number of operators that can be overloaded this way, and all of -their associated traits live in the [`std::ops`][stdops] module. Check out its -documentation for the full list. + + + +同じ方法でオーバーロード可能な演算子が多数あります、 +それらに対応したトレイトは [`std::ops`][stdops] モジュール内に存在します。 +全てのオーバーロード可能な演算子と対応するトレイトについては [`std::ops`][stdops] のドキュメントを読んで確認して下さい。 [stdops]: ../std/ops/index.html -Implementing these traits follows a pattern. Let’s look at [`Add`][add] in more -detail: + + +それらのトレイトの実装はパターンに沿っています。 [`Add`][add] トレイトを詳しく見ていきましょう: ```rust # mod foo { @@ -62,9 +68,11 @@ pub trait Add { [add]: ../std/ops/trait.Add.html -There’s three types in total involved here: the type you `impl Add` for, `RHS`, -which defaults to `Self`, and `Output`. For an expression `let z = x + y`, `x` -is the `Self` type, `y` is the RHS, and `z` is the `Self::Output` type. + + + +関連する3つの型が存在します: `impl Add` を実装するもの、 デフォルトは `Self` の `RHS`、 そうして `Output` 。 +式 `let z = x + y` については `x` は `Self` 型 `y` は RHS、 `z` は `Self::Output` 型となります。 ```rust # struct Point; @@ -79,17 +87,21 @@ impl Add for Point { } ``` -will let you do this: + +上のコードによって以下の様に書けるようになります: ```rust,ignore let p: Point = // ... let x: f64 = p + 2i32; ``` -# Using operator traits in generic structs + +# オペレータトレイトをジェネリック構造体で使う -Now that we know how operator traits are defined, we can define our `HasArea` -trait and `Square` struct from the [traits chapter][traits] more generically: + + +オペレータトレイトがどのように定義されているかについて学びましたので、 +[トレイトについての章][traits] の `HasArea` トレイトと `Square` 構造体をさらに一般的に定義することができます: [traits]: traits.html @@ -124,16 +136,23 @@ fn main() { } ``` -For `HasArea` and `Square`, we just declare a type parameter `T` and replace -`f64` with it. The `impl` needs more involved modifications: + + +`HasArea` と `Square` について、型パラメータ `T` を宣言し `f64` で置換しました。 +`impl` はさらに関連する変形を必要とします。 ```ignore impl HasArea for Square where T: Mul + Copy { ... } ``` -The `area` method requires that we can multiply the sides, so we declare that -type `T` must implement `std::ops::Mul`. Like `Add`, mentioned above, `Mul` -itself takes an `Output` parameter: since we know that numbers don't change -type when multiplied, we also set it to `T`. `T` must also support copying, so -Rust doesn't try to move `self.side` into the return value. + + + + + +`area` メソッドは辺を掛け算することができることを要求しています、 +そのため型 `T` が `std::ops::Mul` を実装指定なければならないと宣言しています。 +`Add` と同じように、上で説明したように、 +`Mul` は `Output` パラメータを取ります: 数値を掛け算した時に型が変わらないことを知っていますので、 `Output` も `T` と設定します。 +また `T` はRustが `self.side` を返り値にムーブするのをを試みないようにコピーをサポートしていなければなりません。 From 16d6072171cc0bcb241017ef2ba59b59c65a3c41 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Thu, 11 Feb 2016 23:36:16 +0900 Subject: [PATCH 3/6] Fix translation. --- 1.6/ja/book/operators-and-overloading.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index 5b2b88dd..6e8bd1de 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -5,8 +5,8 @@ -Rustは制限された形での演算子オーバーロードを許可しており、いくつかのオーバーロード可能な演算子が存在します。 -型同士の間の演算子をサポートするための特定のトレイトが存在し、それらを実装することで演算子をオーバーロードすることができます。 +Rustは制限された形式での演算子オーバーロードを提供しており、オーバーロード可能な演算子がいくつか存在します。 +型同士の間の演算子をサポートするためのトレイトが存在し、それらを実装することで演算子をオーバーロードすることができます。 例えば、 `+` の演算子は `Add` トレイトを利用することでオーバーロードすることができます: @@ -54,7 +54,7 @@ fn main() { -それらのトレイトの実装はパターンに沿っています。 [`Add`][add] トレイトを詳しく見ていきましょう: +それらのトレイトの実装はパターンに従います。 [`Add`][add] トレイトを詳しく見ていきましょう: ```rust # mod foo { @@ -71,8 +71,8 @@ pub trait Add { -関連する3つの型が存在します: `impl Add` を実装するもの、 デフォルトは `Self` の `RHS`、 そうして `Output` 。 -式 `let z = x + y` については `x` は `Self` 型 `y` は RHS、 `z` は `Self::Output` 型となります。 +関連する3つの型が存在します: `impl Add` を実装するもの、 デフォルトが `Self` の `RHS`、 そして `Output` 。 +例えば、式 `let z = x + y` においては `x` は `Self` 型 `y` は RHS、 `z` は `Self::Output` 型となります。 ```rust # struct Point; @@ -139,7 +139,7 @@ fn main() { `HasArea` と `Square` について、型パラメータ `T` を宣言し `f64` で置換しました。 -`impl` はさらに関連する変形を必要とします。 +`impl` はさらに関連するモディフィケーションを必要とします: ```ignore impl HasArea for Square @@ -151,8 +151,7 @@ impl HasArea for Square -`area` メソッドは辺を掛け算することができることを要求しています、 -そのため型 `T` が `std::ops::Mul` を実装指定なければならないと宣言しています。 -`Add` と同じように、上で説明したように、 -`Mul` は `Output` パラメータを取ります: 数値を掛け算した時に型が変わらないことを知っていますので、 `Output` も `T` と設定します。 -また `T` はRustが `self.side` を返り値にムーブするのをを試みないようにコピーをサポートしていなければなりません。 +`area` メソッドは辺を掛ける事が可能なことを必要としています。 +そのため型 `T` が `std::ops::Mul` を実装していなければならないと宣言しています。 +上で説明した `Add` と同様に、`Mul` は `Output` パラメータを取ります: 数値を掛け算した時に型が変わらないことを知っていますので、 `Output` も `T` と設定します。 +また `T` は、Rustが `self.side` を返り値にムーブするのを試みないようにコピーをサポートしている必要があります。 From 66abde88dc5e538c2bf223109f5cf75dbcc95f56 Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Thu, 11 Feb 2016 23:51:18 +0900 Subject: [PATCH 4/6] Little fix translation --- 1.6/ja/book/operators-and-overloading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index 6e8bd1de..c8acb46f 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -41,7 +41,7 @@ fn main() { `main` 中で、2つの `Point` に対して `+` を使うことができます、 -これは `Point` にたいして `Add` を実装したためです。 +これは `Point` に対して `Add` を実装したためです。 From 2b5991a0f46e57910c32c067ae5754f2a8c3a75d Mon Sep 17 00:00:00 2001 From: Pocket7878 Date: Thu, 11 Feb 2016 23:53:57 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BA=8B=20->=20=E3=81=93=E3=81=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.6/ja/book/operators-and-overloading.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index c8acb46f..f844f855 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -151,7 +151,7 @@ impl HasArea for Square -`area` メソッドは辺を掛ける事が可能なことを必要としています。 +`area` メソッドは辺を掛けることが可能なことを必要としています。 そのため型 `T` が `std::ops::Mul` を実装していなければならないと宣言しています。 上で説明した `Add` と同様に、`Mul` は `Output` パラメータを取ります: 数値を掛け算した時に型が変わらないことを知っていますので、 `Output` も `T` と設定します。 また `T` は、Rustが `self.side` を返り値にムーブするのを試みないようにコピーをサポートしている必要があります。 From af5e588b5806a515a907d50619a27211b5943efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E4=BA=80=E7=9C=9E=E6=80=9C?= Date: Fri, 12 Feb 2016 11:43:57 +0900 Subject: [PATCH 6/6] translate comment --- 1.6/ja/book/operators-and-overloading.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/1.6/ja/book/operators-and-overloading.md b/1.6/ja/book/operators-and-overloading.md index f844f855..46bd64ee 100644 --- a/1.6/ja/book/operators-and-overloading.md +++ b/1.6/ja/book/operators-and-overloading.md @@ -81,7 +81,8 @@ impl Add for Point { type Output = f64; fn add(self, rhs: i32) -> f64 { - // add an i32 to a Point and get an f64 +# // // add an i32 to a Point and get an f64 + // i32をPointに加算しf64を返す # 1.0 } }