1+ % パターン Patterns
12<!--
23 % Patterns
34-->
4- % パターン Patterns
55<!-- Patterns are quite common in Rust. -->
66パターンはRustにおいて極めて一般的な方法です。
77<!-- We use them in [variable
@@ -14,7 +14,7 @@ bindings][bindings], [match statements][match], and other places, too.-->
1414
1515<!-- A quick refresher: you can match against literals directly, and `_` acts as an
1616‘any’ case: -->
17- 簡単な復習: パターンはリテラルに対しては直接マッチさせることができます。また、` _ ` は' any' 型として振る舞います。
17+ 簡単な復習: パターンはリテラルに対しては直接マッチさせることができます。また、 ` _ ` は「 any」 型として振る舞います。
1818
1919``` rust
2020let x = 1 ;
6262# 多重パターンマッチ
6363
6464<!-- You can match multiple patterns with `|`: -->
65- ` | ` を使うと、多重パターンマッチが導入出来ます。
65+ ` | ` を使うと、多重パターンマッチが導入出来ます。
6666
6767
6868``` rust
@@ -76,7 +76,7 @@ match x {
7676```
7777
7878<!-- This prints `one or two`.-->
79- これは、` one or two ` を出力します。
79+ これは、 ` one or two ` を出力します。
8080
8181<!-- # Destructuring -->
8282# デストラクチャ
@@ -133,7 +133,7 @@ match origin {
133133```
134134
135135<!-- This prints `x is 0`. -->
136- これは` x is 0 ` を出力します。
136+ これは ` x is 0 ` を出力します。
137137
138138<!-- You can do this kind of match on any member, not just the first:-->
139139どのメンバーに対してもこの種のマッチを行うことが出来ます。たとえ最初ではなくても。
@@ -152,7 +152,7 @@ match origin {
152152```
153153
154154<!-- This prints `y is 0`. -->
155- これは` y is 0 ` を出力します。
155+ これは ` y is 0 ` を出力します。
156156
157157<!-- This ‘destructuring’ behavior works on any compound data type, like
158158[tuples][tuples] or [enums][enums]. -->
@@ -166,10 +166,10 @@ match origin {
166166# バインディングの無視
167167
168168<!-- You can use `_` in a pattern to disregard the type and value.-->
169- パターン内の型や値を無視するために` _ ` を使うことが出来ます。
169+ パターン内の型や値を無視するために ` _ ` を使うことが出来ます。
170170
171171<!-- For example, here’s a `match` against a `Result<T, E>`: -->
172- 例として、` Result<T, E> ` に対して` match ` を適用してみましょう。
172+ 例として、 ` Result<T, E> ` に対して ` match ` を適用してみましょう。
173173
174174``` rust
175175# let some_value : Result <i32 , & 'static str > = Err (" There was an error" );
@@ -182,10 +182,10 @@ match some_value {
182182<!-- In the first arm, we bind the value inside the `Ok` variant to `value`. But
183183in the `Err` arm, we use `_` to disregard the specific error, and just print
184184a general error message. -->
185- 最初の部分では、` Ok ` ヴァリアント内の値を` value ` に結びつけています。しかし、` Err ` 部分ですと、特定のエラーを避けるために、また標準エラーメッセージを表示するために` _ ` を使っています。
185+ 最初の部分では、 ` Ok ` ヴァリアント内の値を ` value ` に結びつけています。しかし、 ` Err ` 部分ですと、特定のエラーを避けるために、また標準エラーメッセージを表示するために ` _ ` を使っています。
186186<!-- `_` is valid in any pattern that creates a binding. This can be useful to
187187ignore parts of a larger structure: -->
188- ` _ ` はバインディングを伴うどんなパターンに於いても有効です。これは大きな構造の一部分を無視する際に有用です。
188+ ` _ ` はバインディングを伴うどんなパターンに於いても有効です。これは大きな構造の一部分を無視する際に有用です。
189189
190190``` rust
191191fn coordinate () -> (i32 , i32 , i32 ) {
@@ -198,9 +198,9 @@ let (x, _, z) = coordinate();
198198
199199<!-- Here, we bind the first and last element of the tuple to `x` and `z`, but
200200ignore the middle element. -->
201- ここでは、タプルの最初と最後の要素を` x ` と ` z ` に結びつけています。
201+ ここでは、タプルの最初と最後の要素を ` x ` と ` z ` に結びつけています。
202202<!-- Similarly, you can use `..` in a pattern to disregard multiple values. -->
203- 同様に、` .. ` でパターン内の複数の値を無視することが出来ます。
203+ 同様に、 ` .. ` でパターン内の複数の値を無視することが出来ます。
204204
205205``` rust
206206enum OptionalTuple {
@@ -217,13 +217,13 @@ match x {
217217```
218218
219219<!-- This prints `Got a tuple!`. -->
220- これは ` Got a tuple! ` を出力します。
220+ これは ` Got a tuple! ` を出力します。
221221
222222<!-- # ref and ref mut -->
223223# ref と ref mut
224224
225225<!-- If you want to get a [reference][ref], use the `ref` keyword:-->
226- もし[ リファレンス] [ ref ] を取得したいときは、` ref ` キーワードを使いましょう。
226+ もし[ リファレンス] [ ref ] を取得したいときは、 ` ref ` キーワードを使いましょう。
227227
228228``` rust
229229let x = 5 ;
@@ -234,14 +234,14 @@ match x {
234234```
235235
236236<!-- This prints `Got a reference to 5`. -->
237- これは` Got a reference to 5 ` を出力します。
237+ これは ` Got a reference to 5 ` を出力します。
238238
239239[ ref ] : references-and-borrowing.html
240240
241241<!-- Here, the `r` inside the `match` has the type `&i32`. In other words, the `ref`
242242keyword _creates_ a reference, for use in the pattern. If you need a mutable
243243reference, `ref mut` will work in the same way: -->
244- ここで、` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると、` ref ` キーワードがリファレンスを _ 作ります_ 。
244+ ここで、 ` match ` 内の ` r ` は ` &i32 ` 型を持っています。言い換えると、 ` ref ` キーワードがリファレンスを _ 作ります_ 。
245245
246246``` rust
247247let mut x = 5 ;
@@ -267,9 +267,9 @@ match x {
267267```
268268
269269<!-- This prints `one through five`. -->
270- これは` one through five ` を出力します。
270+ これは ` one through five ` を出力します。
271271<!-- Ranges are mostly used with integers and `char`s: -->
272- レンジは大体、整数か` char ` 型で使われます。
272+ レンジは大体、整数か ` char ` 型で使われます。
273273
274274``` rust
275275let x = '💅' ;
@@ -282,13 +282,13 @@ match x {
282282```
283283
284284<!-- This prints `something else`. -->
285- これは` something else ` を出力します。
285+ これは ` something else ` を出力します。
286286
287287<!-- # Bindings -->
288288# バインディング
289289
290290<!-- You can bind values to names with `@`: -->
291- ` @ ` で値を名前と結びつけることが出来ます。
291+ ` @ ` で値を名前と結びつけることが出来ます。
292292
293293``` rust
294294let x = 1 ;
@@ -301,7 +301,7 @@ match x {
301301
302302<!-- This prints `got a range element 1`. This is useful when you want to
303303do a complicated match of part of a data structure: -->
304- これは` got a range element 1 ` を出力します。
304+ これは ` got a range element 1 ` を出力します。
305305データ構造の一部に対する複雑なマッチが欲しいときに有用です。
306306
307307``` rust
@@ -319,10 +319,10 @@ match x {
319319```
320320
321321<!-- This prints `Some("Steve")`: we’ve bound the inner `name` to `a`.-->
322- これは` Some("Steve") ` を出力します。内側の` name ` を ` a ` に結びつけます。
322+ これは ` Some("Steve") ` を出力します。内側の ` name ` を ` a ` に結びつけます。
323323<!-- If you use `@` with `|`, you need to make sure the name is bound in each part
324324of the pattern: -->
325- もし` | ` で ` @ ` を使うときは、パターンのそれぞれの部分が名前と結びついているか確認する必要があります。
325+ もし ` | ` で ` @ ` を使うときは、パターンのそれぞれの部分が名前と結びついているか確認する必要があります。
326326
327327
328328``` rust
@@ -338,7 +338,7 @@ match x {
338338# ガード
339339
340340<!-- You can introduce ‘match guards’ with `if`: -->
341- ` if ` を使うことでマッチガードを導入することが出来ます。
341+ ` if ` を使うことでマッチガードを導入することが出来ます。
342342
343343``` rust
344344enum OptionalInt {
@@ -356,10 +356,10 @@ match x {
356356```
357357
358358<!-- This prints `Got an int!`. -->
359- これは` Got an int! ` を出力します。
359+ これは ` Got an int! ` を出力します。
360360
361361<!-- If you’re using `if` with multiple patterns, the `if` applies to both sides:-->
362- 多重パターンで` if ` を使うと、` if ` は両方に適用されます。
362+ 多重パターンで ` if ` を使うと、 ` if ` は両方に適用されます。
363363
364364``` rust
365365let x = 4 ;
@@ -373,7 +373,7 @@ match x {
373373
374374<!-- This prints `no`, because the `if` applies to the whole of `4 | 5`, and not to
375375just the `5`. In other words, the precedence of `if` behaves like this: -->
376- これは` no ` を出力します。なぜなら` if ` は ` 4 | 5 ` 全体に適用されるのであって、` 5 ` 単独に対してではないからです。つまり、` if ` 節は以下のように振舞います。
376+ これは ` no ` を出力します。なぜなら ` if ` は ` 4 | 5 ` 全体に適用されるのであって、 ` 5 ` 単独に対してではないからです。つまり、 ` if ` 節は以下のように振舞います。
377377
378378``` text
379379(4 | 5) if y => ...
0 commit comments