Skip to content

Commit be3f4fd

Browse files
committed
Roughly Translated.
1 parent 11733ca commit be3f4fd

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

1.6/ja/book/match.md

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,36 @@ match x {
3838

3939
[patterns]: patterns.html
4040

41-
So what’s the big advantage? Well, there are a few. First of all, `match`
42-
enforces ‘exhaustiveness checking’. Do you see that last arm, the one with the
43-
underscore (`_`)? If we remove that arm, Rust will give us an error:
41+
<!-- So what’s the big advantage? Well, there are a few. First of all, `match` -->
42+
<!-- enforces ‘exhaustiveness checking’. Do you see that last arm, the one with the -->
43+
<!-- underscore (`_`)? If we remove that arm, Rust will give us an error: -->
44+
`match` を使う利点は何でしょうか? いくつか有りますが、
45+
まず一つ目としては `match` をつかうことで,「完全性チェック」が実施されます。
46+
上のコードで、最後のアンダースコア( `_` )を用いている分岐があるのがわかりますか?
47+
もし、その分岐を削除した場合、Rustは以下の様なエラーを発生させます:
4448

4549
```text
4650
error: non-exhaustive patterns: `_` not covered
4751
```
4852

49-
In other words, Rust is trying to tell us we forgot a value. Because `x` is an
50-
integer, Rust knows that it can have a number of different values – for
51-
example, `6`. Without the `_`, however, there is no arm that could match, and
52-
so Rust refuses to compile the code. `_` acts like a ‘catch-all arm’. If none
53-
of the other arms match, the arm with `_` will, and since we have this
54-
catch-all arm, we now have an arm for every possible value of `x`, and so our
55-
program will compile successfully.
56-
57-
`match` is also an expression, which means we can use it on the right-hand
58-
side of a `let` binding or directly where an expression is used:
53+
<!-- In other words, Rust is trying to tell us we forgot a value. Because `x` is an -->
54+
<!-- integer, Rust knows that it can have a number of different values – for -->
55+
<!-- example, `6`. Without the `_`, however, there is no arm that could match, and -->
56+
<!-- so Rust refuses to compile the code. `_` acts like a ‘catch-all arm’. If none -->
57+
<!-- of the other arms match, the arm with `_` will, and since we have this -->
58+
<!-- catch-all arm, we now have an arm for every possible value of `x`, and so our -->
59+
<!-- program will compile successfully. -->
60+
言い換えると、Rustは値を忘れていることを伝えようとしているのです。
61+
なぜなら `x` は整数であるため、Rustは `x` は多くの異なる値を取ることができることを知っています。
62+
例えば、 `6` などがそれにに当たります。
63+
もし `_` がなかった場合、 `6` にマッチする分岐が存在しない異なります、そのためRustはコンパイルを通しません。
64+
`_` は「全てキャッチする分岐」のように振る舞います。
65+
もし他の分岐がどれもマッチしなかった場合、 `_` の分岐が実行されることになります、
66+
この全てキャッチする分岐が存在するため、 `x` が取り得るすべての値について分岐を持っていることなり、コンパイルが成功します。
67+
68+
<!-- `match` is also an expression, which means we can use it on the right-hand -->
69+
<!-- side of a `let` binding or directly where an expression is used: -->
70+
`match` は式でも有ります、これはつまり `let` 束縛の右側や式が使われているところで利用することができるということを意味しています。
5971

6072
```rust
6173
let x = 5;
@@ -70,12 +82,15 @@ let number = match x {
7082
};
7183
```
7284

73-
Sometimes it’s a nice way of converting something from one type to another.
85+
<!-- Sometimes it’s a nice way of converting something from one type to another. -->
86+
`match` はしばしば、ある型からある型へ変換するための良い手段になりまうす。
7487

75-
# Matching on enums
88+
<!-- # Matching on enums -->
89+
# 列挙型にたいするマッチ
7690

77-
Another important use of the `match` keyword is to process the possible
78-
variants of an enum:
91+
<!-- Another important use of the `match` keyword is to process the possible -->
92+
<!-- variants of an enum: -->
93+
`match` の他の重要な利用方法としてはenumの取り得るバリアントを処理することがあります:
7994

8095
```rust
8196
enum Message {
@@ -99,12 +114,17 @@ fn process_message(msg: Message) {
99114
}
100115
```
101116

102-
Again, the Rust compiler checks exhaustiveness, so it demands that you
103-
have a match arm for every variant of the enum. If you leave one off, it
104-
will give you a compile-time error unless you use `_`.
105-
106-
Unlike the previous uses of `match`, you can’t use the normal `if`
107-
statement to do this. You can use the [`if let`][if-let] statement,
108-
which can be seen as an abbreviated form of `match`.
117+
<!-- Again, the Rust compiler checks exhaustiveness, so it demands that you -->
118+
<!-- have a match arm for every variant of the enum. If you leave one off, it -->
119+
<!-- will give you a compile-time error unless you use `_`. -->
120+
繰り返しますが、Rustコンパイラは完全性のチェックを行い、enumのすべてのバリアントに対して、
121+
マッチする分岐が存在することを要求します。
122+
もし、一つでもマッチする分岐のないバリアントを残している場合、 `_` を用いなければコンパイルエラーが発生します。
123+
124+
<!-- Unlike the previous uses of `match`, you can’t use the normal `if` -->
125+
<!-- statement to do this. You can use the [`if let`][if-let] statement, -->
126+
<!-- which can be seen as an abbreviated form of `match`. -->
127+
上で説明した値に対する `match` の利用とはことなり、enumに対するマッチに `if` を用いることはできません。
128+
enumに対するマッチに [`if let`][if-let] 文を用いることが可能です、 `if let``match` の短縮形と捉えることができます。
109129

110130
[if-let]: if-let.html

0 commit comments

Comments
 (0)