Skip to content

Commit 851792a

Browse files
authored
Merge pull request #172 from kdnakt/translate-question_mark
Translate untranslated lines in question_mark.md
2 parents 5e49aad + 75f5ac6 commit 851792a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/std/result/question_mark.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# `?`
22

3+
<!--
34
Chaining results using match can get pretty untidy; luckily, the `?` operator
45
can be used to make things pretty again. `?` is used at the end of an expression
56
returning a `Result`, and is equivalent to a match expression, where the
67
`Err(err)` branch expands to an early `return Err(From::from(err))`, and the `Ok(ok)`
78
branch expands to an `ok` expression.
9+
-->
10+
マッチを利用して結果をチェインするのは中々面倒です。
11+
幸いなことに、`?`マクロを使用すればイケてるコードに戻すことができます。
12+
`?``Result`を返す式の末尾で使います。
13+
`Err(err)`の分岐が`return Err(From::from(err))`という早期リターンに展開され、
14+
`Ok(ok)`の分岐が`ok`の式に展開されるようなマッチ式と等価です。
815

916
```rust,editable,ignore,mdbook-runnable
1017
mod checked {
@@ -42,11 +49,14 @@ mod checked {
4249
}
4350
4451
// Intermediate function
52+
// 中間関数
4553
fn op_(x: f64, y: f64) -> MathResult {
4654
// if `div` "fails", then `DivisionByZero` will be `return`ed
55+
// `div`が"失敗"したら、`DivisionByZero`が`return`される。
4756
let ratio = div(x, y)?;
4857
4958
// if `ln` "fails", then `NonPositiveLogarithm` will be `return`ed
59+
// もし`ln`が"失敗"したら、`NonPositiveLogarithm`が`return`される。
5060
let ln = ln(ratio)?;
5161
5262
sqrt(ln)
@@ -72,7 +82,11 @@ fn main() {
7282
}
7383
```
7484

85+
<!--
7586
Be sure to check the [documentation][docs],
7687
as there are many methods to map/compose `Result`.
88+
-->
89+
[公式ドキュメント][docs]をチェックすることをオススメします。
90+
`Result`型を扱う関数や`Result`型のメソッドが多く挙げられています。
7791

7892
[docs]: https://doc.rust-lang.org/std/result/index.html

0 commit comments

Comments
 (0)