Skip to content

Commit 48e7e58

Browse files
committed
Merge branch 'master' into variable-bindings
2 parents 4a9f9ad + fb41721 commit 48e7e58

14 files changed

+1100
-504
lines changed

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+
重要なことなので繰り返しますが、ポインタを戻り値の最適化のために使うべきではありません。呼び出し側が戻り値をどのように使うかを選択できるようにしましょう。

1.6/ja/book/if.md

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,73 @@
11
% if
2+
<!-- % if -->
23

3-
Rust’s take on `if` is not particularly complex, but it’s much more like the
4-
`if` you’ll find in a dynamically typed language than in a more traditional
5-
systems language. So let’s talk about it, to make sure you grasp the nuances.
4+
<!-- Rust’s take on `if` is not particularly complex, but it’s much more like the -->
5+
<!-- `if` you’ll find in a dynamically typed language than in a more traditional -->
6+
<!-- systems language. So let’s talk about it, to make sure you grasp the nuances. -->
7+
Rustにおける `if` の扱いはさほど複雑ではありませんが、伝統的なシステムプログラミング言語のそれに比べて、
8+
動的型付け言語でみられる `if` にずっと近いものになっています。そのニュアンスをしっかり理解できるよう、
9+
さっそく説明していきましょう。
610

7-
`if` is a specific form of a more general concept, the ‘branch’. The name comes
8-
from a branch in a tree: a decision point, where depending on a choice,
9-
multiple paths can be taken.
11+
<!-- `if` is a specific form of a more general concept, the ‘branch’. The name comes -->
12+
<!-- from a branch in a tree: a decision point, where depending on a choice, -->
13+
<!-- multiple paths can be taken. -->
14+
`if` は一般化されたコンセプト、「分岐(branch)」の特別な形式です。この名前は木の枝(branch)を由来とし:
15+
取りうる複数のパスから、選択の決定を行うポイントを表します。
1016

11-
In the case of `if`, there is one choice that leads down two paths:
17+
<!-- In the case of `if`, there is one choice that leads down two paths: -->
18+
`if` の場合は、続く2つのパスから1つを選択します。
1219

1320
```rust
1421
let x = 5;
1522

1623
if x == 5 {
17-
println!("x is five!");
24+
# // println!("x is five!");
25+
println!("x は 5 です!");
1826
}
1927
```
2028

21-
If we changed the value of `x` to something else, this line would not print.
22-
More specifically, if the expression after the `if` evaluates to `true`, then
23-
the block is executed. If it’s `false`, then it is not.
29+
<!-- If we changed the value of `x` to something else, this line would not print. -->
30+
<!-- More specifically, if the expression after the `if` evaluates to `true`, then -->
31+
<!-- the block is executed. If it’s `false`, then it is not. -->
32+
仮に `x` を別の値へと変更すると、この行は表示されません。より正確に言うなら、
33+
`if` のあとにくる式が `true` に評価された場合に、ブロックが実行されます。
34+
`false` の場合、ブロックは実行されません。
2435

25-
If you want something to happen in the `false` case, use an `else`:
36+
<!-- If you want something to happen in the `false` case, use an `else`: -->
37+
`false` の場合にも何かをしたいなら、 `else` を使います:
2638

2739
```rust
2840
let x = 5;
2941

3042
if x == 5 {
31-
println!("x is five!");
43+
# // println!("x is five!");
44+
println!("x は 5 です!");
3245
} else {
33-
println!("x is not five :(");
46+
# // println!("x is not five :(");
47+
println!("x は 5 ではありません :(");
3448
}
3549
```
3650

37-
If there is more than one case, use an `else if`:
51+
<!-- If there is more than one case, use an `else if`: -->
52+
場合分けが複数あるときは、 `else if` を使います:
3853

3954
```rust
4055
let x = 5;
4156

4257
if x == 5 {
43-
println!("x is five!");
58+
# // println!("x is five!");
59+
println!("x は 5 です!");
4460
} else if x == 6 {
45-
println!("x is six!");
61+
# // println!("x is six!");
62+
println!("x は 6 です!");
4663
} else {
47-
println!("x is not five or six :(");
64+
# // println!("x is not five or six :(");
65+
println!("x は 5 でも 6 でもありません :(");
4866
}
4967
```
5068

51-
This is all pretty standard. However, you can also do this:
69+
<!-- This is all pretty standard. However, you can also do this: -->
70+
全くもって普通ですね。しかし、次のような使い方もできるのです:
5271

5372
```rust
5473
let x = 5;
@@ -60,14 +79,18 @@ let y = if x == 5 {
6079
}; // y: i32
6180
```
6281

63-
Which we can (and probably should) write like this:
82+
<!-- Which we can (and probably should) write like this: -->
83+
次のように書くこともできます(そして、大抵はこう書くべきです):
6484

6585
```rust
6686
let x = 5;
6787

6888
let y = if x == 5 { 10 } else { 15 }; // y: i32
6989
```
7090

71-
This works because `if` is an expression. The value of the expression is the
72-
value of the last expression in whichever branch was chosen. An `if` without an
73-
`else` always results in `()` as the value.
91+
<!-- This works because `if` is an expression. The value of the expression is the -->
92+
<!-- value of the last expression in whichever branch was chosen. An `if` without an -->
93+
<!-- `else` always results in `()` as the value. -->
94+
これが出来るのは `if` が式であるためです。その式の値は、選択された分岐中の最後の式の値となります。
95+
`else` のない `if` では、その値は常に `()` となります。
96+

1.6/ja/book/ownership.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<!-- become quite acquainted. Ownership is how Rust achieves its largest goal, -->
77
<!-- memory safety. There are a few distinct concepts, each with its own -->
88
<!-- chapter: -->
9-
このガイドはRustの所有権システムの3つの解説の1つです
9+
このガイドはRustの所有権システムの3つの解説の1つ目です
1010
これはRustの最も独特で注目されている機能です。そして、Rust開発者はそれについて高度に精通しておくべきです。
1111
所有権こそはRustがその最大の目標、メモリ安全性を得るための方法です。
1212
そこにはいくつかの別個の概念があり、各概念が独自の章を持ちます。

0 commit comments

Comments
 (0)