1- % Match
2-
3- Often, a simple [ ` if ` ] [ if ] /` else ` isn’t enough, because you have more than two
4- possible options. Also, conditions can get quite complex. Rust
5- has a keyword, ` match ` , that allows you to replace complicated ` if ` /` else `
6- groupings with something more powerful. Check it out:
1+ % マッチ
2+ <!-- % Match -->
3+
4+ <!-- Often, a simple [`if`][if]/`else` isn’t enough, because you have more than two -->
5+ <!-- possible options. Also, conditions can get quite complex. Rust -->
6+ <!-- has a keyword, `match`, that allows you to replace complicated `if`/`else` -->
7+ <!-- groupings with something more powerful. Check it out: -->
8+ しばしば、2つ以上の可能な処理が存在するために単純な [ ` if ` ] [ if ] /` else ` では充分でない時があります。
9+ また、条件が非常に複雑になる場合が有ります。
10+ Rustはキーワード ` match ` を持っており、複雑な ` if ` /` else ` のグループをもっと強力なもので置き換えることができます。
11+ 以下の例を見てみましょう:
712
813``` rust
914let x = 5 ;
@@ -20,11 +25,16 @@ match x {
2025
2126[ if ] : if.html
2227
23- ` match ` takes an expression and then branches based on its value. Each ‘arm’ of
24- the branch is of the form ` val => expression ` . When the value matches, that arm’s
25- expression will be evaluated. It’s called ` match ` because of the term ‘pattern
26- matching’, which ` match ` is an implementation of. There’s an [ entire section on
27- patterns] [ patterns ] that covers all the patterns that are possible here.
28+ <!-- `match` takes an expression and then branches based on its value. Each ‘arm’ of -->
29+ <!-- the branch is of the form `val => expression`. When the value matches, that arm’s -->
30+ <!-- expression will be evaluated. It’s called `match` because of the term ‘pattern -->
31+ <!-- matching’, which `match` is an implementation of. There’s an [entire section on -->
32+ <!-- patterns][patterns] that covers all the patterns that are possible here. -->
33+ ` match ` は一つの式とその式の値に基づく複数のブランチを引数に取ります。
34+ 一つ一つの「分岐」は ` val => expression ` という形式を取ります。
35+ 値がマッチした時に、対応する分岐の式が評価されます。
36+ このような式が ` match ` と呼ばれるのは「パターンマッチ」に由来します。
37+ 可能なすべてのパターンについて説明した、[ パターンの説明のために書かれたセクション] [ patterns ] が存在します。
2838
2939[ patterns ] : patterns.html
3040
0 commit comments