Skip to content

Commit 30025bd

Browse files
committed
Merge branch 'master' into markdown-syntax-space
2 parents 981e511 + f7c78ff commit 30025bd

File tree

109 files changed

+6739
-3438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6739
-3438
lines changed

1.6/ja/book/SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* [はじめる](getting-started.md)
44
* [Rustを学ぶ](learn-rust.md)
55
* [数当てゲーム](guessing-game.md)
6-
* [晩餐する哲学者](dining-philosophers.md)
6+
* [食事する哲学者](dining-philosophers.md)
77
* [他言語と共存する](rust-inside-other-languages.md)
88
* [シンタックスとセマンティクス](syntax-and-semantics.md)
99
* [変数束縛](variable-bindings.md)
@@ -15,7 +15,7 @@
1515
* [所有権](ownership.md)
1616
* [参照と借用](references-and-borrowing.md)
1717
* [ライフタイム](lifetimes.md)
18-
* [可変性](mutability.md)
18+
* [ミュータビリティ](mutability.md)
1919
* [構造体](structs.md)
2020
* [列挙型](enums.md)
2121
* [マッチ](match.md)

1.6/ja/book/advanced-linking.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ $ ldd example
9595
<!-- Static linking is supported via an alternative `libc`, [`musl`](http://www.musl-libc.org). You can compile -->
9696
<!-- your own version of Rust with `musl` enabled and install it into a custom -->
9797
<!-- directory with the instructions below: -->
98-
スタティックリンクは代わりの `libc` である[`musl`](http://www.musl-libc.org/)によってサポートされています。
98+
スタティックリンクは代わりの `libc` である [`musl`](http://www.musl-libc.org/) によってサポートされています。
9999
以下の手順に従い、 `musl` を有効にした独自バージョンのRustをコンパイルして独自のディレクトリにインストールすることができます。
100100

101101
```text
@@ -142,7 +142,7 @@ $ du -h musldist/bin/rustc
142142
<!-- You now have a build of a `musl`-enabled Rust! Because we've installed it to a -->
143143
<!-- custom prefix we need to make sure our system can find the binaries and appropriate -->
144144
<!-- libraries when we try and run it: -->
145-
これで`musl`が有効になったRustのビルドが手に入りました!
145+
これで `musl` が有効になったRustのビルドが手に入りました!
146146
独自のプレフィックスを付けてインストールしたので、試しに実行するときにはシステムがバイナリと適切なライブラリを見付けられることを確かめなければなりません。
147147

148148
```text

1.6/ja/book/associated-types.md

Lines changed: 86 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
% Associated Types
2-
3-
Associated types are a powerful part of Rust’s type system. They’re related to
4-
the idea of a ‘type family’, in other words, grouping multiple types together. That
5-
description is a bit abstract, so let’s dive right into an example. If you want
6-
to write a `Graph` trait, you have two types to be generic over: the node type
7-
and the edge type. So you might write a trait, `Graph<N, E>`, that looks like
8-
this:
1+
% 関連型
2+
<!-- % Associated Types -->
3+
4+
<!-- Associated types are a powerful part of Rust’s type system. They’re related to -->
5+
<!-- the idea of a ‘type family’, in other words, grouping multiple types together. That -->
6+
<!-- description is a bit abstract, so let’s dive right into an example. If you want -->
7+
<!-- to write a `Graph` trait, you have two types to be generic over: the node type -->
8+
<!-- and the edge type. So you might write a trait, `Graph<N, E>`, that looks like -->
9+
<!-- this: -->
10+
関連型は、Rust型システムの強力な部分です。関連型は、「型族」という概念と関連が有り、
11+
言い換えると、複数の型をグループ化するものです。
12+
この説明はすこし抽象的なので、実際の例を見ていきましょう。
13+
例えば、 `Graph` トレイトを定義したいとしましょう、このときジェネリックになる2つの型: 頂点の型、辺の型 が存在します。
14+
そのため、以下のように `Graph<N, E>` と書きたくなるでしょう:
915

1016
```rust
1117
trait Graph<N, E> {
@@ -15,19 +21,24 @@ trait Graph<N, E> {
1521
}
1622
```
1723

18-
While this sort of works, it ends up being awkward. For example, any function
19-
that wants to take a `Graph` as a parameter now _also_ needs to be generic over
20-
the `N`ode and `E`dge types too:
24+
<!-- While this sort of works, it ends up being awkward. For example, any function -->
25+
<!-- that wants to take a `Graph` as a parameter now _also_ needs to be generic over -->
26+
<!-- the `N`ode and `E`dge types too: -->
27+
たしかに上のようなコードは動作しますが、この `Graph` の定義は少し扱いづらいです。
28+
たとえば、任意の `Graph` を引数に取る関数は、 _同時に_ 頂点 `N` と辺 `E` についてもジェネリックとなることになります:
2129

2230
```rust,ignore
2331
fn distance<N, E, G: Graph<N, E>>(graph: &G, start: &N, end: &N) -> u32 { ... }
2432
```
2533

26-
Our distance calculation works regardless of our `Edge` type, so the `E` stuff in
27-
this signature is just a distraction.
34+
<!-- Our distance calculation works regardless of our `Edge` type, so the `E` stuff in -->
35+
<!-- this signature is just a distraction. -->
36+
この距離を計算する関数distanceは、辺の型に関わらず動作します、そのためシグネチャに含まれる `E` に関連する部分は邪魔でしかありません。
2837

29-
What we really want to say is that a certain `E`dge and `N`ode type come together
30-
to form each kind of `Graph`. We can do that with associated types:
38+
<!-- What we really want to say is that a certain `E`dge and `N`ode type come together -->
39+
<!-- to form each kind of `Graph`. We can do that with associated types: -->
40+
本当に表現したいことは、それぞれのグラフ( `Graph` )は辺( `E` )や頂点( `N` )で構成されているということです。
41+
それは、以下のように関連型を用いて表現することができます:
3142

3243
```rust
3344
trait Graph {
@@ -40,19 +51,25 @@ trait Graph {
4051
}
4152
```
4253

43-
Now, our clients can be abstract over a given `Graph`:
54+
<!-- Now, our clients can be abstract over a given `Graph`: -->
55+
このようにすると、`Graph` を使った関数は以下のように書くことができます:
4456

4557
```rust,ignore
4658
fn distance<G: Graph>(graph: &G, start: &G::N, end: &G::N) -> u32 { ... }
4759
```
4860

49-
No need to deal with the `E`dge type here!
61+
<!-- No need to deal with the `E`dge type here! -->
62+
もう `E` について扱う必要はありません!
63+
5064

51-
Let’s go over all this in more detail.
65+
<!-- Let’s go over all this in more detail. -->
66+
もっと詳しく見ていきましょう。
5267

53-
## Defining associated types
68+
<!-- ## Defining associated types -->
69+
## 関連型を定義する
5470

55-
Let’s build that `Graph` trait. Here’s the definition:
71+
<!-- Let’s build that `Graph` trait. Here’s the definition: -->
72+
早速、`Graph` トレイトを定義しましょう。以下がその定義です:
5673

5774
```rust
5875
trait Graph {
@@ -64,12 +81,15 @@ trait Graph {
6481
}
6582
```
6683

67-
Simple enough. Associated types use the `type` keyword, and go inside the body
68-
of the trait, with the functions.
84+
<!-- Simple enough. Associated types use the `type` keyword, and go inside the body -->
85+
<!-- of the trait, with the functions. -->
86+
非常にシンプルですね。関連型には `type` キーワードを使い、そしてトレイトの本体や関数で利用します。
6987

70-
These `type` declarations can have all the same thing as functions do. For example,
71-
if we wanted our `N` type to implement `Display`, so we can print the nodes out,
72-
we could do this:
88+
<!-- These `type` declarations can have all the same thing as functions do. For example, -->
89+
<!-- if we wanted our `N` type to implement `Display`, so we can print the nodes out, -->
90+
<!-- we could do this: -->
91+
これらの `type` 宣言は、関数で利用できるものと同じものが全て利用できます。
92+
たとえば、 `N` 型が `Display` を実装していて欲しい時、つまり私達が頂点を出力したい時、以下のようにして指定することができます:
7393

7494
```rust
7595
use std::fmt;
@@ -83,10 +103,13 @@ trait Graph {
83103
}
84104
```
85105

86-
## Implementing associated types
106+
<!-- ## Implementing associated types -->
107+
## 関連型を実装する
87108

88-
Just like any trait, traits that use associated types use the `impl` keyword to
89-
provide implementations. Here’s a simple implementation of Graph:
109+
<!-- Just like any trait, traits that use associated types use the `impl` keyword to -->
110+
<!-- provide implementations. Here’s a simple implementation of Graph: -->
111+
通常のトレイトと同様に、関連型を使っているトレイトは実装するために `impl` を利用します。
112+
以下は、シンプルなGraphの実装例です:
90113

91114
```rust
92115
# trait Graph {
@@ -115,23 +138,34 @@ impl Graph for MyGraph {
115138
}
116139
```
117140

118-
This silly implementation always returns `true` and an empty `Vec<Edge>`, but it
119-
gives you an idea of how to implement this kind of thing. We first need three
120-
`struct`s, one for the graph, one for the node, and one for the edge. If it made
121-
more sense to use a different type, that would work as well, we’re just going to
122-
use `struct`s for all three here.
141+
<!-- This silly implementation always returns `true` and an empty `Vec<Edge>`, but it -->
142+
<!-- gives you an idea of how to implement this kind of thing. We first need three -->
143+
<!-- `struct`s, one for the graph, one for the node, and one for the edge. If it made -->
144+
<!-- more sense to use a different type, that would work as well, we’re just going to -->
145+
<!-- use `struct`s for all three here. -->
146+
この奇妙な実装は、つねに `true` と空の `Vec<Edge>` を返しますますが、どのように定義したら良いかのアイデアをくれます。
147+
まず、はじめに3つの `struct` が必要です、ひとつはグラフのため、そしてひとつは頂点のため、そしてもうひとつは辺のため。
148+
もし異なる型を利用することが適切ならば、そのようにすると良いでしょう、今回はこの3つの `struct` を用います。
149+
123150

124-
Next is the `impl` line, which is just like implementing any other trait.
151+
<!-- Next is the `impl` line, which is just like implementing any other trait. -->
152+
次は `impl` の行です、これは他のトレイトを実装するときと同様です。
125153

126-
From here, we use `=` to define our associated types. The name the trait uses
127-
goes on the left of the `=`, and the concrete type we’re `impl`ementing this
128-
for goes on the right. Finally, we use the concrete types in our function
129-
declarations.
154+
<!-- From here, we use `=` to define our associated types. The name the trait uses -->
155+
<!-- goes on the left of the `=`, and the concrete type we’re `impl`ementing this -->
156+
<!-- for goes on the right. Finally, we use the concrete types in our function -->
157+
<!-- declarations. -->
158+
そして、`=` を関連型を定義するために利用します。
159+
トレイトが利用する名前は `=` の左側にある名前で、実装に用いる具体的な型は右側にあるものになります。
160+
最後に、具体的な型を関数の宣言に利用します。
130161

131-
## Trait objects with associated types
162+
<!-- ## Trait objects with associated types -->
163+
## 関連型を伴うトレイト
132164

133-
There’s one more bit of syntax we should talk about: trait objects. If you
134-
try to create a trait object from an associated type, like this:
165+
<!-- There’s one more bit of syntax we should talk about: trait objects. If you -->
166+
<!-- try to create a trait object from an associated type, like this: -->
167+
すこし触れておきたい構文: トレイトオブジェクト が有ります。
168+
もし、トレイトオブジェクトを以下のように関連型から作成しようとした場合:
135169

136170
```rust,ignore
137171
# trait Graph {
@@ -157,7 +191,8 @@ let graph = MyGraph;
157191
let obj = Box::new(graph) as Box<Graph>;
158192
```
159193

160-
You’ll get two errors:
194+
<!-- You’ll get two errors: -->
195+
以下の様なエラーが発生します:
161196

162197
```text
163198
error: the value of the associated type `E` (from the trait `main::Graph`) must
@@ -170,8 +205,10 @@ let obj = Box::new(graph) as Box<Graph>;
170205
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171206
```
172207

173-
We can’t create a trait object like this, because we don’t know the associated
174-
types. Instead, we can write this:
208+
<!-- We can’t create a trait object like this, because we don’t know the associated -->
209+
<!-- types. Instead, we can write this: -->
210+
上のようにしてトレイトオブジェクトを作ることはできません、なぜなら関連型について知らないからです
211+
代わりに以下のように書くことができます:
175212

176213
```rust
177214
# trait Graph {
@@ -197,6 +234,8 @@ let graph = MyGraph;
197234
let obj = Box::new(graph) as Box<Graph<N=Node, E=Edge>>;
198235
```
199236

200-
The `N=Node` syntax allows us to provide a concrete type, `Node`, for the `N`
201-
type parameter. Same with `E=Edge`. If we didn’t provide this constraint, we
202-
couldn’t be sure which `impl` to match this trait object to.
237+
<!-- The `N=Node` syntax allows us to provide a concrete type, `Node`, for the `N` -->
238+
<!-- type parameter. Same with `E=Edge`. If we didn’t provide this constraint, we -->
239+
<!-- couldn’t be sure which `impl` to match this trait object to. -->
240+
`N=Node` 構文を用いて型パラメータ `N` にたいして具体的な型 `Node` を指定することができます、`E=Edge` についても同様です。
241+
もしこの制約を指定しなかった場合、このトレイトオブジェクトに対してどの `impl` がマッチするのか定まりません。

1.6/ja/book/attributes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn check() {
5757
この関数は `#[test]` によってマークされており、これは [テスト][tests] を走らせた時に実行されるという特別な意味になります。
5858
通常通りにコンパイルをした場合は、コンパイル結果に含まれません。この関数は今やテスト関数なのです。
5959

60-
[テスト]: testing.html
60+
[tests]: testing.html
6161

6262
<!-- Attributes may also have additional data: -->
6363
アトリビュートは以下のように、追加のデータを持つことができます:
@@ -84,4 +84,4 @@ Rustのアトリビュートは様々なことに利用されます。
8484
すべてのアトリビュートのリストは [リファレンス][reference] に載っています。
8585
現在は、Rustコンパイラーによって定義されている以外の独自のアトリビュートを作成することは許可されていません。
8686

87-
[リファレンス]: ../reference.html#attributes
87+
[reference]: ../reference.html#attributes

1.6/ja/book/box-syntax-and-patterns.md

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
% Box Syntax and Patterns
1+
% Box構文とパターン
2+
<!-- % Box Syntax and Patterns -->
23

3-
Currently the only stable way to create a `Box` is via the `Box::new` method.
4-
Also it is not possible in stable Rust to destructure a `Box` in a match
5-
pattern. The unstable `box` keyword can be used to both create and destructure
6-
a `Box`. An example usage would be:
4+
<!-- Currently the only stable way to create a `Box` is via the `Box::new` method. -->
5+
<!-- Also it is not possible in stable Rust to destructure a `Box` in a match -->
6+
<!-- pattern. The unstable `box` keyword can be used to both create and destructure -->
7+
<!-- a `Box`. An example usage would be: -->
8+
今のところ、安定版において `Box` を作成する唯一の方法は `Box::new` メソッドです。安定版のRustではパターンマッチで `Box` を分解することもできません。不安定版の `box` キーワードは `Box` の作成と分解の両方に使えます。使い方は以下の通りです。
79

810
```rust
911
#![feature(box_syntax, box_patterns)]
@@ -25,14 +27,17 @@ fn main() {
2527
}
2628
```
2729

28-
Note that these features are currently hidden behind the `box_syntax` (box
29-
creation) and `box_patterns` (destructuring and pattern matching) gates
30-
because the syntax may still change in the future.
30+
<!-- Note that these features are currently hidden behind the `box_syntax` (box -->
31+
<!-- creation) and `box_patterns` (destructuring and pattern matching) gates -->
32+
<!-- because the syntax may still change in the future. -->
33+
注記: 将来的にこの構文は変わる可能性があるため、現時点でこれらのフィーチャは `box_syntax` (boxの作成)、 `box_patterns` (分解とパターンマッチ)を明示しなければ使えません。
3134

32-
# Returning Pointers
35+
<!-- # Returning Pointers -->
36+
# ポインタ返し
3337

34-
In many languages with pointers, you'd return a pointer from a function
35-
so as to avoid copying a large data structure. For example:
38+
<!-- In many languages with pointers, you'd return a pointer from a function -->
39+
<!-- so as to avoid copying a large data structure. For example: -->
40+
ポインタを持つ多くのプログラミング言語では、巨大なデータ構造のコピーを避けるため、関数からポインタを返してきました。例えば以下のように書くことができます。
3641

3742
```rust
3843
struct BigStruct {
@@ -57,10 +62,12 @@ fn main() {
5762
}
5863
```
5964

60-
The idea is that by passing around a box, you're only copying a pointer, rather
61-
than the hundred `i32`s that make up the `BigStruct`.
65+
<!-- The idea is that by passing around a box, you're only copying a pointer, rather -->
66+
<!-- than the hundred `i32`s that make up the `BigStruct`. -->
67+
考え方としては、boxで渡すことで `BigStruct` を構成する100個の `i32` の代わりにポインタのみのコピーで済む、というものです。
6268

63-
This is an antipattern in Rust. Instead, write this:
69+
<!-- This is an antipattern in Rust. Instead, write this: -->
70+
これはRustではアンチパターンです。代わりに以下のように書きます。
6471

6572
```rust
6673
#![feature(box_syntax)]
@@ -87,14 +94,17 @@ fn main() {
8794
}
8895
```
8996

90-
This gives you flexibility without sacrificing performance.
97+
<!-- This gives you flexibility without sacrificing performance. -->
98+
このように書くことでパフォーマンスを犠牲にすることなく、柔軟性を確保することができます。
9199

92-
You may think that this gives us terrible performance: return a value and then
93-
immediately box it up ?! Isn't this pattern the worst of both worlds? Rust is
94-
smarter than that. There is no copy in this code. `main` allocates enough room
95-
for the `box`, passes a pointer to that memory into `foo` as `x`, and then
96-
`foo` writes the value straight into the `Box<T>`.
100+
<!-- You may think that this gives us terrible performance: return a value and then -->
101+
<!-- immediately box it up ?! Isn't this pattern the worst of both worlds? Rust is -->
102+
<!-- smarter than that. There is no copy in this code. `main` allocates enough room -->
103+
<!-- for the `box`, passes a pointer to that memory into `foo` as `x`, and then -->
104+
<!-- `foo` writes the value straight into the `Box<T>`. -->
105+
このコードはひどいパフォーマンス低下をもたらすと感じるかもしれません。値を返して即座にboxに入れるなんて?! このパターンは悪いところどりになっているのでは? Rustはもう少し賢いため、このコードでコピーは発生しません。 `main` 内では `box` のために十分なメモリ領域を確保し、そのメモリへのポインタを `foo``x` として渡します。 `foo` はその値を直接 `Box<T>` (訳注: すなわち `y` )の中に書き込みます。
97106

98-
This is important enough that it bears repeating: pointers are not for
99-
optimizing returning values from your code. Allow the caller to choose how they
100-
want to use your output.
107+
<!-- This is important enough that it bears repeating: pointers are not for -->
108+
<!-- optimizing returning values from your code. Allow the caller to choose how they -->
109+
<!-- want to use your output. -->
110+
重要なことなので繰り返しますが、ポインタを戻り値の最適化のために使うべきではありません。呼び出し側が戻り値をどのように使うかを選択できるようにしましょう。

0 commit comments

Comments
 (0)