44<!-- `struct`s are a way of creating more complex data types. For example, if we were
55doing calculations involving coordinates in 2D space, we would need both an `x`
66and a `y` value: -->
7- ` struct ` はより複雑なデータ型を作る方法の1つです。例えば、もし私たちが2次元空間の座標に関する計算を行っているとして、` x ` と ` y ` 、両方の値が必要になるでしょう。
7+ ` struct ` はより複雑なデータ型を作る方法の1つです。例えば、もし私たちが2次元空間の座標に関する計算を行っているとして、 ` x ` と ` y ` 、両方の値が必要になるでしょう。
88
99``` rust
1010let origin_x = 0 ;
1111let origin_y = 0 ;
1212```
1313
1414<!-- A `struct` lets us combine these two into a single, unified datatype: -->
15- ` struct ` でこれら2つを1つのデータ型にまとめることができます。
15+ ` struct ` でこれら2つを1つのデータ型にまとめることができます。
1616
1717``` rust
1818struct Point {
@@ -30,20 +30,20 @@ fn main() {
3030<!-- There’s a lot going on here, so let’s break it down. We declare a `struct` with
3131the `struct` keyword, and then with a name. By convention, `struct`s begin with
3232a capital letter and are camel cased: `PointInSpace`, not `Point_In_Space`. -->
33- ここで多くの情報が出てきましたから、順番に見ていきましょう。まず、` struct ` キーワードを使って構造体とその名前を宣言しています。慣習により、構造体は初めが大文字のキャメルケースで記述しています。` PointInSpace ` であり、` Point_In_Space ` ではありません。
33+ ここで多くの情報が出てきましたから、順番に見ていきましょう。まず、 ` struct ` キーワードを使って構造体とその名前を宣言しています。慣習により、構造体は初めが大文字のキャメルケースで記述しています。 ` PointInSpace ` であり、 ` Point_In_Space ` ではありません。
3434
3535<!-- We can create an instance of our `struct` via `let`, as usual, but we use a `key:
3636value` style syntax to set each field. The order doesn’t need to be the same as
3737in the original declaration. -->
38- いつものように、` let ` で ` struct ` のインスタンスを作ることができますが、ここでは` key: value ` スタイルの構文でそれぞれのフィールドに値をセットしています。順序は元の宣言と同じである必要はありません。
38+ いつものように、 ` let ` で ` struct ` のインスタンスを作ることができますが、ここでは ` key: value ` スタイルの構文でそれぞれのフィールドに値をセットしています。順序は元の宣言と同じである必要はありません。
3939
4040<!-- Finally, because fields have names, we can access the field through dot
4141notation: `origin.x`. -->
42- 最後に、作成された構造体のフィールドは名前を持つため、` origin.x ` というようにドット表記でアクセスできます。
42+ 最後に、作成された構造体のフィールドは名前を持つため、 ` origin.x ` というようにドット表記でアクセスできます。
4343
4444<!-- The values in `struct`s are immutable by default, like other bindings in Rust.
4545Use `mut` to make them mutable -->
46- Rustの他の束縛のように、` struct ` が持つ値はイミュータブルがデフォルトです。` mut ` を使うと値をミュータブルにできます。
46+ Rustの他の束縛のように、 ` struct ` が持つ値はイミュータブルがデフォルトです。 ` mut ` を使うと値をミュータブルにできます。
4747
4848``` rust
4949struct Point {
@@ -61,7 +61,7 @@ fn main() {
6161```
6262
6363<!-- This will print `The point is at (5, 0)`. -->
64- これは` The point is at (5, 0) ` と出力されます。
64+ これは ` The point is at (5, 0) ` と出力されます。
6565
6666<!-- Rust does not support field mutability at the language level, so you cannot
6767write something like this: -->
@@ -105,7 +105,7 @@ fn main() {
105105
106106<!-- A `struct` can include `..` to indicate that you want to use a copy of some
107107other `struct` for some of the values. For example: -->
108- ` struct ` の初期化時には、値の一部を他の構造体からコピーしたいことを示す` .. ` を含めることができます。例えば、
108+ ` struct ` の初期化時には、値の一部を他の構造体からコピーしたいことを示す ` .. ` を含めることができます。例えば、
109109
110110``` rust
111111struct Point3d {
@@ -139,7 +139,7 @@ let point = Point3d { z: 1, x: 2, .. origin };
139139<!-- Rust has another data type that’s like a hybrid between a [tuple][tuple] and a
140140`struct`, called a ‘tuple struct’. Tuple structs have a name, but
141141their fields don’t:-->
142- Rustには「タプル構造体」と呼ばれる、[ タプル] [ tuple ] と` struct ` のハイブリットのようなデータ型があります。タプル構造体自体には名前がありますが、そのフィールドには名前がありません。
142+ Rustには「タプル構造体」と呼ばれる、[ タプル] [ tuple ] と ` struct ` のハイブリットのようなデータ型があります。タプル構造体自体には名前がありますが、そのフィールドには名前がありません。
143143
144144``` rust
145145struct Color (i32 , i32 , i32 );
@@ -160,7 +160,7 @@ let origin = Point(0, 0, 0);
160160
161161<!-- It is almost always better to use a `struct` than a tuple struct. We would write
162162`Color` and `Point` like this instead: -->
163- ほとんどの場合タプル構造体よりも` struct ` を使ったほうが良いです。` Color ` や ` Point ` はこのようにも書けます。
163+ ほとんどの場合タプル構造体よりも ` struct ` を使ったほうが良いです。 ` Color ` や ` Point ` はこのようにも書けます。
164164
165165``` rust
166166struct Color {
@@ -178,7 +178,7 @@ struct Point {
178178
179179<!-- Now, we have actual names, rather than positions. Good names are important,
180180and with a `struct`, we have actual names. -->
181- 今、私たちはフィールドの位置ではなく実際のフィールドの名前を持っています。良い名前は重要で、` struct ` を使うということは、実際に名前を持っているということです。
181+ 今、私たちはフィールドの位置ではなく実際のフィールドの名前を持っています。良い名前は重要で、 ` struct ` を使うということは、実際に名前を持っているということです。
182182
183183> 訳注: 原文を元に噛み砕くと、「タプルはフィールドの並びによって区別され、構造体はフィールドの名前によって区別されます。これはタプルと構造体の最たる違いであり、構造体を持つことは名前を付けられたデータの集まりを持つことに等しいため、構造体における名前付けは重要です。」といった所でしょうか。
184184
@@ -200,13 +200,13 @@ println!("length is {} inches", integer_length);
200200<!-- As you can see here, you can extract the inner integer type through a
201201destructuring `let`, just as with regular tuples. In this case, the
202202`let Inches(integer_length)` assigns `10` to `integer_length`. -->
203- 上記の通り、` let ` を使って分解することで、標準のタプルと同じように内部の整数型を取り出すことができます。
204- このケースでは` let Inches(integer_length) ` が ` integer_length ` へ ` 10 ` を束縛します。
203+ 上記の通り、 ` let ` を使って分解することで、標準のタプルと同じように内部の整数型を取り出すことができます。
204+ このケースでは ` let Inches(integer_length) ` が ` integer_length ` へ ` 10 ` を束縛します。
205205
206206# Unit-like 構造体
207207
208208<!-- You can define a `struct` with no members at all: -->
209- あなたは全くメンバを持たない` struct ` を定義できます。
209+ あなたは全くメンバを持たない ` struct ` を定義できます。
210210
211211``` rust
212212struct Electron ;
@@ -217,14 +217,14 @@ let x = Electron;
217217<!-- Such a `struct` is called ‘unit-like’ because it resembles the empty
218218tuple, `()`, sometimes called ‘unit’. Like a tuple struct, it defines a
219219new type. -->
220- 空のタプルである` () ` は時々` unit ` と呼ばれ、それに似ていることからこのような構造体を` unit-like ` と呼んでいます。タプル構造体のように、これは新しい型を定義します。
220+ 空のタプルである ` () ` は時々 ` unit ` と呼ばれ、それに似ていることからこのような構造体を ` unit-like ` と呼んでいます。タプル構造体のように、これは新しい型を定義します。
221221
222222<!-- This is rarely useful on its own (although sometimes it can serve as a
223223marker type), but in combination with other features, it can become
224224useful. For instance, a library may ask you to create a structure that
225225implements a certain [trait][trait] to handle events. If you don’t have
226226any data you need to store in the structure, you can just create a
227227unit-like `struct`. -->
228- これは単体でもごくまれに役立ちます(もっとも、時々型をマーク代わりとして役立てる程度です)が、他の機能と組み合わせることにより便利になります。例えば、ライブラリはあなたにイベントを処理できる特定の[ トレイト] [ trait ] が実装されたストラクチャの作成を要求するかもしれません。もしそのストラクチャの中に保存すべき値が何もなければ、あなたはダミーのデータを作成する必要はなく、ただunit-likeな` struct ` を作るだけで良いのです。
228+ これは単体でもごくまれに役立ちます(もっとも、時々型をマーク代わりとして役立てる程度です)が、他の機能と組み合わせることにより便利になります。例えば、ライブラリはあなたにイベントを処理できる特定の[ トレイト] [ trait ] が実装されたストラクチャの作成を要求するかもしれません。もしそのストラクチャの中に保存すべき値が何もなければ、あなたはダミーのデータを作成する必要はなく、ただunit-likeな ` struct ` を作るだけで良いのです。
229229
230230[ trait ] : traits.html
0 commit comments