7
7
<!-- Vectors always allocate their data on the heap. -->
8
8
<!-- You can create them with the `vec!` macro: -->
9
9
「ベクタ」は動的な、または「拡張可能な」配列です、標準ライブラリ上で [ ` Vec<T> ` ] [ vec ] として提供されています。
10
- ` T ` はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は[ ジェネリクス] [ generics ] を御覧ください)
10
+ ` T ` はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は[ ジェネリクス] [ generic ] を御覧ください)
11
11
ベクタはデータを常にヒープ上にアロケーションします。
12
12
ベクタは以下のように ` vec! ` マクロを用いて作成できます:
13
13
@@ -18,7 +18,7 @@ let v = vec![1, 2, 3, 4, 5]; // v: Vec<i32>
18
18
<!-- (Notice that unlike the `println!` macro we’ve used in the past, we use square -->
19
19
<!-- brackets `[]` with `vec!` macro. Rust allows you to use either in either situation, -->
20
20
<!-- this is just convention.) -->
21
- (依然使った ` println! ` マクロと異なり、` vec! ` マクロで 角括弧 ` [] ` を利用しました。
21
+ (以前使った ` println! ` マクロと異なり、` vec! ` マクロで 角括弧 ` [] ` を利用しました。
22
22
Rustではどちらの括弧もどちらのシチュエーションでも利用可能であり、解りやすさのためです。
23
23
24
24
<!-- There’s an alternate form of `vec!` for repeating an initial value: -->
@@ -29,34 +29,40 @@ Rustではどちらの括弧もどちらのシチュエーションでも利用
29
29
let v = vec! [0 ; 10 ]; // 0が10個
30
30
```
31
31
32
- ## Accessing elements
32
+ ## 要素へのアクセス
33
33
34
- To get the value at a particular index in the vector, we use ` [] ` s:
34
+ <!-- To get the value at a particular index in the vector, we use `[]`s: -->
35
+ ベクタ中の特定のインデックスの値にアクセスするには ` [] ` を利用します:
35
36
36
37
``` rust
37
38
let v = vec! [1 , 2 , 3 , 4 , 5 ];
38
39
39
40
println! (" The third element of v is {}" , v [2 ]);
40
41
```
41
42
42
- The indices count from ` 0 ` , so the third element is ` v[2] ` .
43
+ <!-- The indices count from `0`, so the third element is `v[2]`.-->
44
+ インデックスは ` 0 ` から始まります、なので三番目の要素は ` v[2] ` となります。
43
45
44
- It’s also important to note that you must index with the ` usize ` type:
46
+ <!-- It’s also important to note that you must index with the `usize` type: -->
47
+ また、インデックスは ` usize ` 型でなければならない点に注意しましょう:
45
48
46
49
``` ignore
47
50
let v = vec![1, 2, 3, 4, 5];
48
51
49
52
let i: usize = 0;
50
53
let j: i32 = 0;
51
54
52
- // works
55
+ # // // works
56
+ // これは動作します
53
57
v[i];
54
58
55
- // doesn’t
59
+ # // // doesn’t
60
+ // 一方、こちらは動作しません
56
61
v[j];
57
62
```
58
63
59
- Indexing with a non-` usize ` type gives an error that looks like this:
64
+ <!-- Indexing with a non-`usize` type gives an error that looks like this: -->
65
+ ` usize ` 型でないインデックスを用いた場合、以下の様なエラーが発生します:
60
66
61
67
``` text
62
68
error: the trait `core::ops::Index<i32>` is not implemented for the type
@@ -67,13 +73,15 @@ note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`
67
73
error: aborting due to previous error
68
74
```
69
75
70
- There’s a lot of punctuation in that message, but the core of it makes sense:
71
- you cannot index with an ` i32 ` .
76
+ <!-- There’s a lot of punctuation in that message, but the core of it makes sense: -->
77
+ <!-- you cannot index with an `i32`. -->
78
+ エラーメッセージ中には多くの点が含まれていますが、一番大切な部分は ` i32 ` をインデックスとして用いることはできないという点です。
72
79
73
- ## Iterating
80
+ ## イテレーティング
74
81
75
- Once you have a vector, you can iterate through its elements with ` for ` . There
76
- are three versions:
82
+ <!-- Once you have a vector, you can iterate through its elements with `for`. There -->
83
+ <!-- are three versions: -->
84
+ ベクタである値に対して ` for ` を用いて以下の様な3つの方法でイテレートすることができます:
77
85
78
86
``` rust
79
87
let mut v = vec! [1 , 2 , 3 , 4 , 5 ];
@@ -91,8 +99,9 @@ for i in v {
91
99
}
92
100
```
93
101
94
- Vectors have many more useful methods, which you can read about in [ their
95
- API documentation] [ vec ] .
102
+ <!-- Vectors have many more useful methods, which you can read about in [their -->
103
+ <!-- API documentation][vec]. -->
104
+ ベクタにはもっと多くの便利なメソッドが定義されています。それらのメソッドについては [ APIドキュメント] [ vec ] で確認することができます。
96
105
97
106
[ vec ] : ../std/vec/index.html
98
107
[ generic ] : generics.html
0 commit comments