Skip to content

Commit 6be1521

Browse files
committed
Roughly Translated.
1 parent c77e786 commit 6be1521

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

1.6/ja/book/vectors.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Vectors always allocate their data on the heap. -->
88
<!-- You can create them with the `vec!` macro: -->
99
「ベクタ」は動的な、または「拡張可能な」配列です、標準ライブラリ上で [`Vec<T>`][vec] として提供されています。
10-
`T` はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は[ジェネリクス][generics]を御覧ください)
10+
`T` はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は[ジェネリクス][generic]を御覧ください)
1111
ベクタはデータを常にヒープ上にアロケーションします。
1212
ベクタは以下のように `vec!` マクロを用いて作成できます:
1313

@@ -18,7 +18,7 @@ let v = vec![1, 2, 3, 4, 5]; // v: Vec<i32>
1818
<!-- (Notice that unlike the `println!` macro we’ve used in the past, we use square -->
1919
<!-- brackets `[]` with `vec!` macro. Rust allows you to use either in either situation, -->
2020
<!-- this is just convention.) -->
21-
(依然使った`println!` マクロと異なり、`vec!` マクロで 角括弧 `[]` を利用しました。
21+
(以前使った`println!` マクロと異なり、`vec!` マクロで 角括弧 `[]` を利用しました。
2222
Rustではどちらの括弧もどちらのシチュエーションでも利用可能であり、解りやすさのためです。
2323

2424
<!-- There’s an alternate form of `vec!` for repeating an initial value: -->
@@ -29,34 +29,40 @@ Rustではどちらの括弧もどちらのシチュエーションでも利用
2929
let v = vec![0; 10]; // 0が10個
3030
```
3131

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

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

3637
```rust
3738
let v = vec![1, 2, 3, 4, 5];
3839

3940
println!("The third element of v is {}", v[2]);
4041
```
4142

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

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

4649
```ignore
4750
let v = vec![1, 2, 3, 4, 5];
4851
4952
let i: usize = 0;
5053
let j: i32 = 0;
5154
52-
// works
55+
# // // works
56+
// これは動作します
5357
v[i];
5458
55-
// doesn’t
59+
# // // doesn’t
60+
// 一方、こちらは動作しません
5661
v[j];
5762
```
5863

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

6167
```text
6268
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`
6773
error: aborting due to previous error
6874
```
6975

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` をインデックスとして用いることはできないという点です。
7279

73-
## Iterating
80+
## イテレーティング
7481

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つの方法でイテレートすることができます:
7785

7886
```rust
7987
let mut v = vec![1, 2, 3, 4, 5];
@@ -91,8 +99,9 @@ for i in v {
9199
}
92100
```
93101

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] で確認することができます。
96105

97106
[vec]: ../std/vec/index.html
98107
[generic]: generics.html

0 commit comments

Comments
 (0)