Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5b875b3

Browse files
committedFeb 4, 2016
generate
1 parent 46cdbab commit 5b875b3

File tree

1 file changed

+67
-29
lines changed

1 file changed

+67
-29
lines changed
 

‎public/1.6/book/vectors.html

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<meta name="generator" content="rustdoc">
7-
<title>Vectors</title>
7+
<title>ベクタ</title>
88

99
<link rel="stylesheet" type="text/css" href="rustbook.css">
1010

@@ -185,29 +185,50 @@
185185
<div id='page'>
186186

187187

188-
<h1 class="title">Vectors</h1>
189-
<p>A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard
190-
library type <a href="../std/vec/index.html"><code>Vec&lt;T&gt;</code></a>. The <code>T</code> means that we can have vectors
191-
of any type (see the chapter on <a href="generics.html">generics</a> for more).
192-
Vectors always allocate their data on the heap.
193-
You can create them with the <code>vec!</code> macro:</p>
188+
<h1 class="title">ベクタ</h1>
189+
<!-- % Vectors -->
190+
191+
<!-- A ‘vector’ is a dynamic or ‘growable’ array, implemented as the standard -->
192+
193+
<!-- library type [`Vec<T>`][vec]. The `T` means that we can have vectors -->
194+
195+
<!-- of any type (see the chapter on [generics][generic] for more). -->
196+
197+
<!-- Vectors always allocate their data on the heap. -->
198+
199+
<!-- You can create them with the `vec!` macro: -->
200+
201+
<p>「ベクタ」は動的な、または「拡張可能な」配列です、標準ライブラリ上で <a href="../std/vec/index.html"><code>Vec&lt;T&gt;</code></a> として提供されています。
202+
<code>T</code> はどんなタイプのベクタをも作成することが可能なことを意味しています。(詳細は<a href="generics.html">ジェネリクス</a>を御覧ください)
203+
ベクタはデータを常にヒープ上にアロケーションします。
204+
ベクタは以下のように <code>vec!</code> マクロを用いて作成できます:</p>
194205
<span class='rusttest'>fn main() {
195206
let v = vec![1, 2, 3, 4, 5]; // v: Vec&lt;i32&gt;
196207
}</span><pre class='rust rust-example-rendered'>
197208
<span class='kw'>let</span> <span class='ident'>v</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='number'>1</span>, <span class='number'>2</span>, <span class='number'>3</span>, <span class='number'>4</span>, <span class='number'>5</span>]; <span class='comment'>// v: Vec&lt;i32&gt;</span></pre>
198209

199-
<p>(Notice that unlike the <code>println!</code> macro we’ve used in the past, we use square
200-
brackets <code>[]</code> with <code>vec!</code> macro. Rust allows you to use either in either situation,
201-
this is just convention.)</p>
210+
<!-- (Notice that unlike the `println!` macro we’ve used in the past, we use square -->
211+
212+
<!-- brackets `[]` with `vec!` macro. Rust allows you to use either in either situation, -->
213+
214+
<!-- this is just convention.) -->
215+
216+
<p>(以前使った<code>println!</code> マクロと異なり、<code>vec!</code> マクロで 角括弧 <code>[]</code> を利用しました。)
217+
Rustではどちらの括弧もどちらのシチュエーションでも利用可能であり、解りやすさのためです。</p>
218+
219+
<!-- There’s an alternate form of `vec!` for repeating an initial value: -->
202220

203-
<p>There’s an alternate form of <code>vec!</code> for repeating an initial value:</p>
221+
<p><code>vec!</code> には初期値の繰り返しを表現するための形式があります:</p>
204222
<span class='rusttest'>fn main() {
205-
let v = vec![0; 10]; // ten zeroes
223+
// let v = vec![0; 10]; // ten zeroes
224+
let v = vec![0; 10]; // 0が10個
206225
}</span><pre class='rust rust-example-rendered'>
207-
<span class='kw'>let</span> <span class='ident'>v</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='number'>0</span>; <span class='number'>10</span>]; <span class='comment'>// ten zeroes</span></pre>
226+
<span class='kw'>let</span> <span class='ident'>v</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='number'>0</span>; <span class='number'>10</span>]; <span class='comment'>// 0が10個</span></pre>
208227

209-
<h2 id='accessing-elements' class='section-header'><a href='#accessing-elements'>Accessing elements</a></h2>
210-
<p>To get the value at a particular index in the vector, we use <code>[]</code>s:</p>
228+
<h2 id='要素へのアクセス' class='section-header'><a href='#要素へのアクセス'>要素へのアクセス</a></h2>
229+
<!-- To get the value at a particular index in the vector, we use `[]`s: -->
230+
231+
<p>ベクタ中の特定のインデックスの値にアクセスするには <code>[]</code> を利用します:</p>
211232
<span class='rusttest'>fn main() {
212233
let v = vec![1, 2, 3, 4, 5];
213234

@@ -217,33 +238,41 @@ <h2 id='accessing-elements' class='section-header'><a href='#accessing-elements'
217238

218239
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;The third element of v is {}&quot;</span>, <span class='ident'>v</span>[<span class='number'>2</span>]);</pre>
219240

220-
<p>The indices count from <code>0</code>, so the third element is <code>v[2]</code>.</p>
241+
<!-- The indices count from `0`, so the third element is `v[2]`.-->
242+
243+
<p>インデックスは <code>0</code> から始まります、なので三番目の要素は <code>v[2]</code> となります。</p>
244+
245+
<!-- It’s also important to note that you must index with the `usize` type: -->
221246

222-
<p>It’s also important to note that you must index with the <code>usize</code> type:</p>
247+
<p>また、インデックスは <code>usize</code> 型でなければならない点に注意しましょう:</p>
223248
<span class='rusttest'>fn main() {
224249
let v = vec![1, 2, 3, 4, 5];
225250

226251
let i: usize = 0;
227252
let j: i32 = 0;
228253

229-
// works
254+
// // works
255+
// これは動作します
230256
v[i];
231257

232-
// doesn’t
258+
// // doesn’t
259+
// 一方、こちらは動作しません
233260
v[j];
234261
}</span><pre class='rust rust-example-rendered'>
235262
<span class='kw'>let</span> <span class='ident'>v</span> <span class='op'>=</span> <span class='macro'>vec</span><span class='macro'>!</span>[<span class='number'>1</span>, <span class='number'>2</span>, <span class='number'>3</span>, <span class='number'>4</span>, <span class='number'>5</span>];
236263

237264
<span class='kw'>let</span> <span class='ident'>i</span>: <span class='ident'>usize</span> <span class='op'>=</span> <span class='number'>0</span>;
238265
<span class='kw'>let</span> <span class='ident'>j</span>: <span class='ident'>i32</span> <span class='op'>=</span> <span class='number'>0</span>;
239266

240-
<span class='comment'>// works</span>
267+
<span class='comment'>// これは動作します</span>
241268
<span class='ident'>v</span>[<span class='ident'>i</span>];
242269

243-
<span class='comment'>// doesn’t</span>
270+
<span class='comment'>// 一方、こちらは動作しません</span>
244271
<span class='ident'>v</span>[<span class='ident'>j</span>];</pre>
245272

246-
<p>Indexing with a non-<code>usize</code> type gives an error that looks like this:</p>
273+
<!-- Indexing with a non-`usize` type gives an error that looks like this: -->
274+
275+
<p><code>usize</code> 型でないインデックスを用いた場合、以下の様なエラーが発生します:</p>
247276

248277
<pre><code class="language-text">error: the trait `core::ops::Index&lt;i32&gt;` is not implemented for the type
249278
`collections::vec::Vec&lt;_&gt;` [E0277]
@@ -253,12 +282,18 @@ <h2 id='accessing-elements' class='section-header'><a href='#accessing-elements'
253282
error: aborting due to previous error
254283
</code></pre>
255284

256-
<p>There’s a lot of punctuation in that message, but the core of it makes sense:
257-
you cannot index with an <code>i32</code>.</p>
285+
<!-- There’s a lot of punctuation in that message, but the core of it makes sense: -->
286+
287+
<!-- you cannot index with an `i32`. -->
258288

259-
<h2 id='iterating' class='section-header'><a href='#iterating'>Iterating</a></h2>
260-
<p>Once you have a vector, you can iterate through its elements with <code>for</code>. There
261-
are three versions:</p>
289+
<p>エラーメッセージ中には多くの点が含まれていますが、一番大切な部分は <code>i32</code> をインデックスとして用いることはできないという点です。</p>
290+
291+
<h2 id='イテレーティング' class='section-header'><a href='#イテレーティング'>イテレーティング</a></h2>
292+
<!-- Once you have a vector, you can iterate through its elements with `for`. There -->
293+
294+
<!-- are three versions: -->
295+
296+
<p>ベクタである値に対して <code>for</code> を用いて以下の様な3つの方法でイテレートすることができます:</p>
262297
<span class='rusttest'>fn main() {
263298
let mut v = vec![1, 2, 3, 4, 5];
264299

@@ -288,8 +323,11 @@ <h2 id='iterating' class='section-header'><a href='#iterating'>Iterating</a></h2
288323
<span class='macro'>println</span><span class='macro'>!</span>(<span class='string'>&quot;Take ownership of the vector and its element {}&quot;</span>, <span class='ident'>i</span>);
289324
}</pre>
290325

291-
<p>Vectors have many more useful methods, which you can read about in <a href="../std/vec/index.html">their
292-
API documentation</a>.</p>
326+
<!-- Vectors have many more useful methods, which you can read about in [their -->
327+
328+
<!-- API documentation][vec]. -->
329+
330+
<p>ベクタにはもっと多くの便利なメソッドが定義されています。それらのメソッドについては <a href="../std/vec/index.html">APIドキュメント</a> で確認することができます。</p>
293331

294332
<script type="text/javascript">
295333
window.playgroundUrl = "https://play.rust-lang.org";

0 commit comments

Comments
 (0)
Please sign in to comment.