Skip to content

Commit 12fe10a

Browse files
authored
Merge pull request #179 from tatsuya6502/operators-and-overloading-1.9
4.32. Operators and Overloading (1.9)
2 parents 8de8c46 + c4fe9f0 commit 12fe10a

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

1.9/ja/book/operators-and-overloading.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<!-- between types, there’s a specific trait that you can implement, which then -->
77
<!-- overloads the operator. -->
88
Rustは制限された形式での演算子オーバーロードを提供しており、オーバーロード可能な演算子がいくつか存在します。
9-
型同士の間の演算子をサポートするためのトレイトが存在し、それらを実装することで演算子をオーバーロードすることができます
9+
型同士の間の演算子をサポートするためのトレイトが存在し、それらを実装することで演算子をオーバーロードできます
1010

1111
<!-- For example, the `+` operator can be overloaded with the `Add` trait: -->
12-
例えば`+` の演算子は `Add` トレイトを利用することでオーバーロードすることができます:
12+
たとえば`+` の演算子は `Add` トレイトでオーバーロードできます:
1313

1414
```rust
1515
use std::ops::Add;
@@ -40,21 +40,22 @@ fn main() {
4040

4141
<!-- In `main`, we can use `+` on our two `Point`s, since we’ve implemented -->
4242
<!-- `Add<Output=Point>` for `Point`. -->
43-
`main` 中で、2つの `Point` に対して `+` を使うことができます、
43+
`main` 中で、2つの `Point` に対して `+` を使えます。
4444
これは `Point` に対して `Add<Output=Point>` を実装したためです。
4545

4646
<!-- There are a number of operators that can be overloaded this way, and all of -->
4747
<!-- their associated traits live in the [`std::ops`][stdops] module. Check out its -->
4848
<!-- documentation for the full list. -->
49-
同じ方法でオーバーロード可能な演算子が多数あります
49+
同じ方法でオーバーロード可能な演算子が多数あります
5050
それらに対応したトレイトは [`std::ops`][stdops] モジュール内に存在します。
5151
全てのオーバーロード可能な演算子と対応するトレイトについては [`std::ops`][stdops] のドキュメントを読んで確認して下さい。
5252

5353
[stdops]: ../std/ops/index.html
5454

5555
<!-- Implementing these traits follows a pattern. Let’s look at [`Add`][add] in more -->
5656
<!-- detail: -->
57-
それらのトレイトの実装はパターンに従います。 [`Add`][add] トレイトを詳しく見ていきましょう:
57+
それらのトレイトの実装は、ある一つのパターンに従います。
58+
[`Add`][add] トレイトを詳しく見ていきましょう:
5859

5960
```rust
6061
# mod foo {
@@ -71,8 +72,8 @@ pub trait Add<RHS = Self> {
7172
<!-- There’s three types in total involved here: the type you `impl Add` for, `RHS`, -->
7273
<!-- which defaults to `Self`, and `Output`. For an expression `let z = x + y`, `x` -->
7374
<!-- is the `Self` type, `y` is the RHS, and `z` is the `Self::Output` type. -->
74-
関連する3つの型が存在します: `impl Add` を実装するもの、 デフォルトが `Self``RHS`、 そして `Output`
75-
例えば、式 `let z = x + y` においては `x``Self``y` は RHS、 `z``Self::Output` 型となります。
75+
関連する3つの型が存在します: `impl Add` を実装するもの、 デフォルトが `Self``RHS`、 そして `Output` です
76+
たとえば、式 `let z = x + y` においては `x``Self``y` は RHS、 `z``Self::Output` 型となります。
7677

7778
```rust
7879
# struct Point;
@@ -101,8 +102,7 @@ let x: f64 = p + 2i32;
101102

102103
<!-- Now that we know how operator traits are defined, we can define our `HasArea` -->
103104
<!-- trait and `Square` struct from the [traits chapter][traits] more generically: -->
104-
オペレータトレイトがどのように定義されているかについて学びましたので、
105-
[トレイトについての章][traits]`HasArea` トレイトと `Square` 構造体をさらに一般的に定義することができます:
105+
オペレータトレイトがどのように定義されているかを学びましたので、[トレイトについての章][traits]`HasArea` トレイトと `Square` 構造体をさらに一般的に定義できます:
106106

107107
[traits]: traits.html
108108

@@ -137,10 +137,10 @@ fn main() {
137137
}
138138
```
139139

140-
<!-- For `HasArea` and `Square`, we just declare a type parameter `T` and replace -->
140+
<!-- For `HasArea` and `Square`, we declare a type parameter `T` and replace -->
141141
<!-- `f64` with it. The `impl` needs more involved modifications: -->
142142
`HasArea``Square` について、型パラメータ `T` を宣言し `f64` で置換しました。
143-
`impl` はさらに関連するモディフィケーションを必要とします:
143+
`impl` はさらに関連する修正を必要とします:
144144

145145
```ignore
146146
impl<T> HasArea<T> for Square<T>
@@ -154,5 +154,6 @@ impl<T> HasArea<T> for Square<T>
154154
<!-- Rust doesn't try to move `self.side` into the return value. -->
155155
`area` メソッドは辺を掛けることが可能なことを必要としています。
156156
そのため型 `T``std::ops::Mul` を実装していなければならないと宣言しています。
157-
上で説明した `Add` と同様に、`Mul``Output` パラメータを取ります: 数値を掛け算した時に型が変わらないことを知っていますので、 `Output``T` と設定します。
157+
上で説明した `Add` と同様に、`Mul``Output` パラメータを取ります:
158+
数値を掛け算した時に型が変わらないことを知っていますので、 `Output``T` と設定します。
158159
また `T` は、Rustが `self.side` を返り値にムーブするのを試みないようにコピーをサポートしている必要があります。

diff-1.6.0..1.9.0/src/doc/book/operators-and-overloading.md

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

0 commit comments

Comments
 (0)