Skip to content

Commit 46cdbab

Browse files
committed
Merge pull request #63 from pocket7878/vectors
Vectors
2 parents 4636803 + 25e25bc commit 46cdbab

File tree

1 file changed

+44
-26
lines changed

1 file changed

+44
-26
lines changed

1.6/ja/book/vectors.md

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,68 @@
1-
% Vectors
2-
3-
A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard
4-
library type [`Vec<T>`][vec]. The `T` means that we can have vectors
5-
of any type (see the chapter on [generics][generic] for more).
6-
Vectors always allocate their data on the heap.
7-
You can create them with the `vec!` macro:
1+
% ベクタ
2+
<!-- % Vectors -->
3+
4+
<!-- A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard -->
5+
<!-- library type [`Vec<T>`][vec]. The `T` means that we can have vectors -->
6+
<!-- of any type (see the chapter on [generics][generic] for more). -->
7+
<!-- Vectors always allocate their data on the heap. -->
8+
<!-- You can create them with the `vec!` macro: -->
9+
「ベクタ」は動的な、または「拡張可能な」配列です、標準ライブラリ上で [`Vec<T>`][vec] として提供されています。
10+
`T` はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は[ジェネリクス][generic]を御覧ください)
11+
ベクタはデータを常にヒープ上にアロケーションします。
12+
ベクタは以下のように `vec!` マクロを用いて作成できます:
813

914
```rust
1015
let v = vec![1, 2, 3, 4, 5]; // v: Vec<i32>
1116
```
1217

13-
(Notice that unlike the `println!` macro we’ve used in the past, we use square
14-
brackets `[]` with `vec!` macro. Rust allows you to use either in either situation,
15-
this is just convention.)
18+
<!-- (Notice that unlike the `println!` macro we’ve used in the past, we use square -->
19+
<!-- brackets `[]` with `vec!` macro. Rust allows you to use either in either situation, -->
20+
<!-- this is just convention.) -->
21+
(以前使った`println!` マクロと異なり、`vec!` マクロで 角括弧 `[]` を利用しました。)
22+
Rustではどちらの括弧もどちらのシチュエーションでも利用可能であり、解りやすさのためです。
1623

17-
There’s an alternate form of `vec!` for repeating an initial value:
24+
<!-- There’s an alternate form of `vec!` for repeating an initial value: -->
25+
`vec!` には初期値の繰り返しを表現するための形式があります:
1826

1927
```rust
20-
let v = vec![0; 10]; // ten zeroes
28+
# // let v = vec![0; 10]; // ten zeroes
29+
let v = vec![0; 10]; // 0が10個
2130
```
2231

23-
## Accessing elements
32+
## 要素へのアクセス
2433

25-
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+
ベクタ中の特定のインデックスの値にアクセスするには `[]` を利用します:
2636

2737
```rust
2838
let v = vec![1, 2, 3, 4, 5];
2939

3040
println!("The third element of v is {}", v[2]);
3141
```
3242

33-
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]` となります。
3445

35-
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` 型でなければならない点に注意しましょう:
3648

3749
```ignore
3850
let v = vec![1, 2, 3, 4, 5];
3951
4052
let i: usize = 0;
4153
let j: i32 = 0;
4254
43-
// works
55+
# // // works
56+
// これは動作します
4457
v[i];
4558
46-
// doesn’t
59+
# // // doesn’t
60+
// 一方、こちらは動作しません
4761
v[j];
4862
```
4963

50-
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` 型でないインデックスを用いた場合、以下の様なエラーが発生します:
5166

5267
```text
5368
error: the trait `core::ops::Index<i32>` is not implemented for the type
@@ -58,13 +73,15 @@ note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`
5873
error: aborting due to previous error
5974
```
6075

61-
There’s a lot of punctuation in that message, but the core of it makes sense:
62-
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` をインデックスとして用いることはできないという点です。
6379

64-
## Iterating
80+
## イテレーティング
6581

66-
Once you have a vector, you can iterate through its elements with `for`. There
67-
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つの方法でイテレートすることができます:
6885

6986
```rust
7087
let mut v = vec![1, 2, 3, 4, 5];
@@ -82,8 +99,9 @@ for i in v {
8299
}
83100
```
84101

85-
Vectors have many more useful methods, which you can read about in [their
86-
API documentation][vec].
102+
<!-- Vectors have many more useful methods, which you can read about in [their -->
103+
<!-- API documentation][vec]. -->
104+
ベクタにはもっと多くの便利なメソッドが定義されています。それらのメソッドについては [APIドキュメント][vec] で確認することができます。
87105

88106
[vec]: ../std/vec/index.html
89107
[generic]: generics.html

0 commit comments

Comments
 (0)