From eb30ffe4df226e65a95de8f1f7306b20b393ea69 Mon Sep 17 00:00:00 2001 From: "Tatsuya Kawano (Circle CI)" Date: Mon, 20 Jun 2016 19:15:38 +0800 Subject: [PATCH 1/4] Update Primitive Types to 1.9 --- 1.9/ja/book/primitive-types.md | 307 +++++++++--------- .../src/doc/book/primitive-types.md | 99 ------ 2 files changed, 159 insertions(+), 247 deletions(-) delete mode 100644 diff-1.6.0..1.9.0/src/doc/book/primitive-types.md diff --git a/1.9/ja/book/primitive-types.md b/1.9/ja/book/primitive-types.md index d9e1de43..75d60f0e 100644 --- a/1.9/ja/book/primitive-types.md +++ b/1.9/ja/book/primitive-types.md @@ -1,18 +1,19 @@ % プリミティブ型 - + - - - - -Rust言語は「プリミティブ」であると考えられるかなりの数の型を持ちます。 + + + + +Rust言語は「プリミティブ」とみなされる多数の型を持ちます。 これはそれらが言語に組み込まれていることを意味します。 -標準ライブラリも同様にそれらの型の上に構築されたかなりの数の便利な型を提供していて、そのような方法でRustは構造化されています。しかし、プリミティブ型が最もプリミティブです。 +Rustの型は構造化されており、標準ライブラリも、プリミティブ型を用いて構築した数多くの便利な型を提供しています。 +しかし、プリミティブ型が最もプリミティブ(基本的で素朴)な型です。 - + # ブーリアン型 - + Rustには `bool` と名付けられた組込みのブーリアン型があります。 それは `true` と `false` という2つの値を持ちます。 @@ -22,55 +23,55 @@ let x = true; let y: bool = false; ``` - -ブーリアンの一般的な使い方は、 [`if` 条件][if] の中で用いるものです。 + +ブーリアンの一般的な使い方は、 [`if` 条件][if] で用いるものです。 [if]: if.html - - -`bool` のさらなるドキュメントは [標準ライブラリのドキュメントの中][bool] で見付けることができます。 + + +`bool` の詳しいドキュメントは [標準ライブラリのドキュメント][bool] にあります。 [bool]: ../std/primitive.bool.html - + # `char` - - + + `char` 型は1つのユニコードのスカラ値を表現します。 -`char` はシングルクオート( `'` )で作ることができます。 +`char` はシングルクオート( `'` )で作られます。 ```rust let x = 'x'; let two_hearts = '💕'; ``` - - + + `char` が1バイトである他の言語と異なり、これはRustの `char` が1バイトではなく4バイトであるということを意味します。 - - -`char` のさらなるドキュメントは [標準ライブラリのドキュメントの中][char] で見付けることができます。 + + +`char` の詳しいドキュメントは [標準ライブラリのドキュメント][char] にあります。 [char]: ../std/primitive.char.html - + # 数値型 - - -Rustにはいくつかのカテゴリの中にたくさんの種類の数値型があります。そのカテゴリは符号ありと符号なし、固定長と可変長、浮動小数点数と整数です。 + + +Rustにはいくつかのカテゴリにたくさんの種類の数値型があります。そのカテゴリは符号ありと符号なし、固定長と可変長、浮動小数点数と整数です。 - - - + + + それらの型はカテゴリとサイズという2つの部分から成ります。 例えば、 `u16` はサイズ16ビットで符号なしの型です。 ビット数を大きくすれば、より大きな数値を扱うことができます。 - + もし数値リテラルがその型を推論させるものを何も持たないのであれば、以下のとおりデフォルトになります。 ```rust @@ -80,8 +81,8 @@ let x = 42; // xはi32型を持つ let y = 1.0; // yはf64型を持つ ``` - - + + これはいろいろな数値型のリストにそれらの標準ライブラリのドキュメントへのリンクを付けたものです。 * [i8](../std/primitive.i8.html) @@ -97,64 +98,64 @@ let y = 1.0; // yはf64型を持つ * [f32](../std/primitive.f32.html) * [f64](../std/primitive.f64.html) - + それらをカテゴリ別に調べましょう。 - + ## 符号ありと符号なし - - - - - + + + + + 整数型には符号ありと符号なしという2つの種類があります。 違いを理解するために、サイズ4ビットの数値を考えましょう。 -符号あり4ビット整数は `-8` から `+7` までの数値を保存することができます。 +符号あり4ビット整数は `-8` から `+7` までの数値を保存できます。 符号ありの数値は「2の補数表現」を使います。 -符号なし4ビット整数は、マイナスを保存する必要がないため、 `0` から `+15` までの値を保存することができます。 +符号なし4ビット整数は、マイナスを保存する必要がないため、 `0` から `+15` までの値を保存できます。 - - - + + + 符号なし(訳注:unsigned)型はそれらのカテゴリに `u` を使い、符号あり型は `i` を使います。 `i` は「整数(訳注:integer)」の頭文字です。 そのため、 `u8` は8ビット符号なし数値、 `i8` は8ビット符号あり数値です。 - + ## 固定長型 - - - -固定長型はそれらの表現の中に特定のビット数を持ちます。 + + + +固定長型はそれらの表現に特定のビット数を持ちます。 指定することのできるビット長は `8` 、 `16` 、 `32` 、 `64` です。 そのため、 `u32` は符号なし32ビット整数、 `i64` は符号あり64ビット整数です。 - + ## 可変長型 - - - -Rustはそのサイズが実行しているマシンのポインタのサイズに依存する型も提供します。 + + + +Rustが提供する型には、そのサイズが実行しているマシンのポインタのサイズに依存するものもあります。 それらの型はカテゴリとして「size」を使い、符号ありと符号なしの種類があります。 これが `isize` と `usize` という2つの型を作ります。 - + ## 浮動小数点型 - - + + Rustは `f32` と `f64` という2つの浮動小数点型を持ちます。 それらはIEEE-754単精度及び倍精度小数点数に対応します。 - + # 配列 - - - + + + 多くのプログラミング言語のように、Rustには何かのシーケンスを表現するためのリスト型があります。 最も基本的なものは *配列* 、固定長の同じ型の要素のリストです。 デフォルトでは、配列はイミュータブルです。 @@ -164,15 +165,15 @@ let a = [1, 2, 3]; // a: [i32; 3] let mut m = [1, 2, 3]; // m: [i32; 3] ``` - - - + + + 配列は `[T; N]` という型を持ちます。 -この `T` 記法については [ジェネリクスのセクションの中][generics] で話します。 +この `T` 記法については [ジェネリクスのセクション][generics] で話します。 `N` は配列の長さのためのコンパイル時の定数です。 - - + + 配列の各要素を同じ値で初期化するための省略表現があります。 この例では、 `a` の各要素は `0` で初期化されます。 @@ -180,8 +181,8 @@ let mut m = [1, 2, 3]; // m: [i32; 3] let a = [0; 20]; // a: [i32; 20] ``` - -配列 `a` の要素の個数は `a.len()` で得ることができます。 + +配列 `a` の要素の個数は `a.len()` で得られます。 ```rust let a = [1, 2, 3]; @@ -189,8 +190,8 @@ let a = [1, 2, 3]; println!("a has {} elements", a.len()); ``` - -配列の特定の要素には *添字記法* でアクセスすることができます。 + +配列の特定の要素には *添字記法* でアクセスできます。 ```rust let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3] @@ -198,90 +199,100 @@ let names = ["Graydon", "Brian", "Niko"]; // names: [&str; 3] println!("The second name is: {}", names[1]); ``` - - - - - - + + + + + + 添字はほとんどのプログラミング言語と同じように0から始まります。そのため、最初の名前は `names[0]` で2つ目の名前は `names[1]` です。 -前の例は `The second name is: Brian` とプリントします。 +前の例は `The second name is: Brian` と表示します。 もし配列に含まれない添字を使おうとすると、エラーが出ます。配列アクセスは実行時に境界チェックを受けます。 他のシステムプログラミング言語では、そのような誤ったアクセスは多くのバグの源となります。 - - -`array` のさらなるドキュメントは [標準ライブラリのドキュメントの中][array] で見付けることができます。 + + +`array` の詳しいドキュメントは [標準ライブラリのドキュメント][array] にあります。 [array]: ../std/primitive.array.html - + # スライス - - - - - + + + + + 「スライス」は他のデータ構造への参照(又は「ビュー」)です。 それらはコピーすることなく配列の要素への安全で効率的なアクセスを許すために便利です。 例えば、メモリに読み込んだファイルの1行だけを参照したいことがあるかもしれません。 性質上、スライスは直接作られるのではなく、既存の変数束縛から作られます。 スライスは定義された長さを持ち、ミュータブルにもイミュータブルにもできます。 - + + +スライスは内部的には、データの先頭へのポインタとデータ長の組み合わせで表現されます。 + + ## スライシング構文 - - - -様々なものからスライスを作るためには `&` と `[]` の組合せを使うことができます。 -`&` はスライスが参照と同じであることを示し、 `[]` はレンジを持ち、スライスの長さを定義します。 + + + + +`&` と `[]` を組合せて使うと、様々なものからスライスが作れます。 +`&` はスライスが、参照と似たものであることを示します(参照については、[後ほど詳細をカバー][references] します)。 +`[]` はレンジを持ち、スライスの長さを定義します。 + +[references]: references-and-borrowing.html ```rust let a = [0, 1, 2, 3, 4]; # // let complete = &a[..]; // A slice containing all of the elements in a let complete = &a[..]; // aに含まれる全ての要素を持つスライス -# // let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3 +# // let middle = &a[1..4]; // A slice of a: only the elements 1, 2, and 3 let middle = &a[1..4]; // 1、2、3のみを要素に持つaのスライス ``` - - + + スライスは型 `&[T]` を持ちます。 [ジェネリクス][generics] をカバーするときにその `T` について話すでしょう。 [generics]: generics.html - - -`slice` のさらなるドキュメントは [標準ライブラリのドキュメントの中][slice] で見付けることができます。 + + +`slice` の詳しいドキュメントは [標準ライブラリのドキュメント][slice] にあります。 [slice]: ../std/primitive.slice.html - + # `str` - - - + + + + Rustの `str` 型は最もプリミティブな文字列型です。 -[サイズ不定型][dst] のように、それはそれ自体で非常に便利なものではありませんが、 [`&str`][strings] のように参照の後ろに置かれたときに便利になります。 +[サイズ不定型][dst] のように、それ自体が非常に便利なものではありませんが、 [`&str`][strings] のように参照の後ろに置かれたときに便利になります。 そのため、それはそのまま置いておきましょう。 +(TODO:翻訳を更新する) [dst]: unsized-types.html [strings]: strings.html - - -`str` のさらなるドキュメントは [標準ライブラリのドキュメントの中][str] で見付けることができます。 + + +`str` の詳しいドキュメントは [標準ライブラリのドキュメント][str] にあります。 [str]: ../std/primitive.str.html - + # タプル - + タプルは固定サイズの順序ありリストです。 このようなものです。 @@ -289,8 +300,8 @@ Rustの `str` 型は最もプリミティブな文字列型です。 let x = (1, "hello"); ``` - - + + 丸括弧とコンマがこの長さ2のタプルを形成します。 これは同じコードですが、型注釈が付いています。 @@ -298,20 +309,20 @@ let x = (1, "hello"); let x: (i32, &str) = (1, "hello"); ``` - - - - - - -見てのとおり、タプルの型はタプルとちょうど同じように見えます。しかし、各位置には値ではなく型名が付いています。 + + + + + + +見てのとおり、タプルの型はタプルと同じように見えます。しかし、各位置には値ではなく型名が付いています。 注意深い読者は、タプルが異なる型の値を含んでいることにも気が付くでしょう。このタプルには `i32` と `&str` が入っています。 システムプログラミング言語では、文字列は他の言語よりも少し複雑です。 -今のところ、 `&str` を *文字列スライス* と読むだけにしましょう。それ以上のことは後で学ぶでしょう。 +今のところ、 `&str` を *文字列スライス* と読みましょう。それ以上のことは後で学ぶでしょう。 - - -もしそれらの持っている型と [アリティ][arity] が同じであれば、あるタプルを他のタプルに割り当てることができます。 + + +もしそれらの持っている型と [アリティ][arity] が同じであれば、あるタプルを他のタプルに割り当てられます。 タプルの長さが同じであれば、それらのタプルのアリティは同じです。 [arity]: glossary.html#arity @@ -323,9 +334,9 @@ let y = (2, 3); // y: (i32, i32) x = y; ``` - - -タプルのフィールドには *分配束縛let* を通じてアクセスすることができます。 + + +タプルのフィールドには *分配束縛let* を通じてアクセスできます。 これが例です。 ```rust @@ -334,24 +345,24 @@ let (x, y, z) = (1, 2, 3); println!("x is {}", x); ``` - - - - - -[前に][let]`let` 文の左辺は単なる束縛の割当てよりももっと強力だと言ったときのことを覚えていますか。 + + + + + +[前に][let]`let` 文の左辺は、単なる束縛の割り当てよりも強力だと言ったときのことを覚えていますか。 ここで説明します。 -`let` の左辺にはパターンを書くことができ、もしそれが右辺とマッチしたならば、複数の束縛を一度に割り当てることができます。 +`let` の左辺にはパターンを書くことができ、もしそれが右辺とマッチしたならば、複数の束縛を一度に割り当てられます。 この場合、 `let` が「分配束縛」、つまりタプルを「分解して」、要素を3つの束縛に割り当てます。 [let]: variable-bindings.html - + このパターンは非常に強力で、後で繰り返し見るでしょう。 - - -コンマを付けることで要素1のタプルを丸括弧の中の値と混同しないように明示することができます。 + + +コンマを付けることで要素1のタプルを丸括弧の値と混同しないように明示できます。 ```rust # // (0,); // single-element tuple @@ -360,10 +371,10 @@ println!("x is {}", x); (0); // 丸括弧に囲まれたゼロ ``` - + ## タプルのインデックス - + タプルのフィールドにはインデックス構文でアクセスすることもできます。 ```rust @@ -376,20 +387,20 @@ let z = tuple.2; println!("x is {}", x); ``` - - + + 配列のインデックスと同じように、それは0から始まります。しかし、配列のインデックスと異なり、それは `[]` ではなく `.` を使います。 - - -タプルのさらなるドキュメントは [標準ライブラリのドキュメントの中][tuple] で見付けることができます。 + + +タプルの詳しいドキュメントは [標準ライブラリのドキュメント][tuple] にあります。 [tuple]: ../std/primitive.tuple.html - + # 関数 - + 関数も型を持ちます! それらはこのようになります。 @@ -399,6 +410,6 @@ fn foo(x: i32) -> i32 { x } let x: fn(i32) -> i32 = foo; ``` - - + + この場合、 `x` は `i32` を受け取り `i32` を戻す関数への「関数ポインタ」です。 diff --git a/diff-1.6.0..1.9.0/src/doc/book/primitive-types.md b/diff-1.6.0..1.9.0/src/doc/book/primitive-types.md deleted file mode 100644 index 921902f2..00000000 --- a/diff-1.6.0..1.9.0/src/doc/book/primitive-types.md +++ /dev/null @@ -1,99 +0,0 @@ ---- a/src/doc/book/primitive-types.md -+++ b/src/doc/book/primitive-types.md -@@ -7,7 +7,7 @@ of these ones, as well, but these are the most primitive. - - # Booleans - --Rust has a built in boolean type, named `bool`. It has two values, `true` and `false`: -+Rust has a built-in boolean type, named `bool`. It has two values, `true` and `false`: - - ```rust - let x = true; -@@ -89,13 +89,13 @@ Unsigned types use a `u` for their category, and signed types use `i`. The `i` - is for ‘integer’. So `u8` is an eight-bit unsigned number, and `i8` is an - eight-bit signed number. - --## Fixed size types -+## Fixed-size types - --Fixed size types have a specific number of bits in their representation. Valid -+Fixed-size types have a specific number of bits in their representation. Valid - bit sizes are `8`, `16`, `32`, and `64`. So, `u32` is an unsigned, 32-bit integer, - and `i64` is a signed, 64-bit integer. - --## Variable sized types -+## Variable-size types - - Rust also provides types whose size depends on the size of a pointer of the - underlying machine. These types have ‘size’ as the category, and come in signed -@@ -160,20 +160,26 @@ documentation][array]. - - A ‘slice’ is a reference to (or “view” into) another data structure. They are - useful for allowing safe, efficient access to a portion of an array without --copying. For example, you might want to reference just one line of a file read -+copying. For example, you might want to reference only one line of a file read - into memory. By nature, a slice is not created directly, but from an existing - variable binding. Slices have a defined length, can be mutable or immutable. - -+Internally, slices are represented as a pointer to the beginning of the data -+and a length. -+ - ## Slicing syntax - - You can use a combo of `&` and `[]` to create a slice from various things. The --`&` indicates that slices are similar to references, and the `[]`s, with a --range, let you define the length of the slice: -+`&` indicates that slices are similar to [references], which we will cover in -+detail later in this section. The `[]`s, with a range, let you define the -+length of the slice: -+ -+[references]: references-and-borrowing.html - - ```rust - let a = [0, 1, 2, 3, 4]; - let complete = &a[..]; // A slice containing all of the elements in a --let middle = &a[1..4]; // A slice of a: just the elements 1, 2, and 3 -+let middle = &a[1..4]; // A slice of a: only the elements 1, 2, and 3 - ``` - - Slices have type `&[T]`. We’ll talk about that `T` when we cover -@@ -189,11 +195,13 @@ documentation][slice]. - # `str` - - Rust’s `str` type is the most primitive string type. As an [unsized type][dst], --it’s not very useful by itself, but becomes useful when placed behind a reference, --like [`&str`][strings]. As such, we’ll just leave it at that. -+it’s not very useful by itself, but becomes useful when placed behind a -+reference, like `&str`. We'll elaborate further when we cover -+[Strings][strings] and [references]. - - [dst]: unsized-types.html - [strings]: strings.html -+[references]: references-and-borrowing.html - - You can find more documentation for `str` [in the standard library - documentation][str]. -@@ -215,11 +223,11 @@ with the type annotated: - let x: (i32, &str) = (1, "hello"); - ``` - --As you can see, the type of a tuple looks just like the tuple, but with each -+As you can see, the type of a tuple looks like the tuple, but with each - position having a type name rather than the value. Careful readers will also - note that tuples are heterogeneous: we have an `i32` and a `&str` in this tuple. - In systems programming languages, strings are a bit more complex than in other --languages. For now, just read `&str` as a *string slice*, and we’ll learn more -+languages. For now, read `&str` as a *string slice*, and we’ll learn more - soon. - - You can assign one tuple into another, if they have the same contained types -@@ -244,7 +252,7 @@ println!("x is {}", x); - ``` - - Remember [before][let] when I said the left-hand side of a `let` statement was more --powerful than just assigning a binding? Here we are. We can put a pattern on -+powerful than assigning a binding? Here we are. We can put a pattern on - the left-hand side of the `let`, and if it matches up to the right-hand side, - we can assign multiple bindings at once. In this case, `let` “destructures” - or “breaks up” the tuple, and assigns the bits to three bindings. -diff --git a/src/doc/book/references-and-borrowing.md b/src/doc/book/references-and-borrowing.md From 4248ae33930e977fe441af0a53dbf46bd8b48b71 Mon Sep 17 00:00:00 2001 From: "Tatsuya Kawano (Circle CI)" Date: Mon, 20 Jun 2016 20:11:51 +0800 Subject: [PATCH 2/4] Update translation for Primitive Types (1.9) --- 1.9/ja/book/primitive-types.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/1.9/ja/book/primitive-types.md b/1.9/ja/book/primitive-types.md index 75d60f0e..a92cbcf5 100644 --- a/1.9/ja/book/primitive-types.md +++ b/1.9/ja/book/primitive-types.md @@ -276,9 +276,8 @@ let middle = &a[1..4]; // 1、2、3のみを要素に持つaのスライス Rustの `str` 型は最もプリミティブな文字列型です。 -[サイズ不定型][dst] のように、それ自体が非常に便利なものではありませんが、 [`&str`][strings] のように参照の後ろに置かれたときに便利になります。 -そのため、それはそのまま置いておきましょう。 -(TODO:翻訳を更新する) +[サイズ不定型][dst] のように、それ単体ではあまり便利ではありませんが、 [`&str`][strings] のように参照の後ろに置かれたときに便利になります。 +[文字列][strings] と [参照][references] についてカバーする際に、より正確に学びましょう。 [dst]: unsized-types.html [strings]: strings.html From f9722b97adc9e7c4e272640e4cbaa6f7a97cdae9 Mon Sep 17 00:00:00 2001 From: "Tatsuya Kawano (Circle CI)" Date: Mon, 20 Jun 2016 20:13:00 +0800 Subject: [PATCH 3/4] Cosmetics on Primitive Types (1.9) --- 1.9/ja/book/primitive-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1.9/ja/book/primitive-types.md b/1.9/ja/book/primitive-types.md index a92cbcf5..23e6a37b 100644 --- a/1.9/ja/book/primitive-types.md +++ b/1.9/ja/book/primitive-types.md @@ -7,7 +7,7 @@ Rust言語は「プリミティブ」とみなされる多数の型を持ちます。 これはそれらが言語に組み込まれていることを意味します。 -Rustの型は構造化されており、標準ライブラリも、プリミティブ型を用いて構築した数多くの便利な型を提供しています。 +Rustの型は構造化されており、標準ライブラリでもプリミティブ型を用いて構築した数多くの便利な型を提供しています。 しかし、プリミティブ型が最もプリミティブ(基本的で素朴)な型です。 From c728dc461b7e1ea9b841f966f8e3cd78d682625c Mon Sep 17 00:00:00 2001 From: "Tatsuya Kawano (Circle CI)" Date: Tue, 21 Jun 2016 08:55:14 +0800 Subject: [PATCH 4/4] Add missing link "references" --- 1.9/ja/book/primitive-types.md | 1 + 1 file changed, 1 insertion(+) diff --git a/1.9/ja/book/primitive-types.md b/1.9/ja/book/primitive-types.md index 23e6a37b..84344979 100644 --- a/1.9/ja/book/primitive-types.md +++ b/1.9/ja/book/primitive-types.md @@ -281,6 +281,7 @@ Rustの `str` 型は最もプリミティブな文字列型です。 [dst]: unsized-types.html [strings]: strings.html +[references]: references-and-borrowing.html