Skip to content

Commit f401943

Browse files
committed
error-handling - apply review comments and suggestions
1 parent 457c264 commit f401943

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

1.6/ja/book/error-handling.md

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ Rustでは戻り値を使います。
3434
というのは、直和型(sum type) とコンビネータから始めることで、Restにおけるエラーハンドリングを徐々に改善していくための動機を与えるからです。
3535
このような構成ですので、もしすでに他の表現力豊かな型システムの経験があるプログラマでしたら、あちこち拾い読みしたくなるかもしれません。
3636

37-
<!-- 用語集候補:combinator -->
38-
39-
<!-- 翻訳メモ:sum type -->
40-
<!-- https://www.quora.com/What-is-a-sum-type -->
41-
<!-- http://d-poppo.nazo.cc/blog/2015/01/union-types/ -->
42-
4337
<!-- * [The Basics](#the-basics) -->
4438
<!-- * [Unwrapping explained](#unwrapping-explained) -->
4539
<!-- * [The `Option` type](#the-option-type) -->
@@ -70,16 +64,16 @@ Rustでは戻り値を使います。
7064
<!-- * [Adding functionality](#adding-functionality) -->
7165
<!-- [The short story](#the-short-story) -->
7266

73-
* [基礎](#the-basics)
74-
* [アンラップ(unwrap) とは](#unwrapping-explained)
75-
* [`Option`](#the-option-type)
76-
* [`Option<T>` 値で構成する](#composing-optiont-values)
77-
* [`Result`](#the-result-type)
78-
* [整数をパースする](#parsing-integers)
79-
* [`Result` 型エイリアスを用いたイディオム](#the-result-type-alias-idiom)
80-
* [小休止:アンラップは悪ではない](#a-brief-interlude-unwrapping-isnt-evil)
67+
* [基礎](#基礎)
68+
* [アンラップ(unwrap) とは](#アンラップunwrap-とは)
69+
* [`Option`](#option-)
70+
* [`Option<T>` 値を合成する](#optiont-値を合成する)
71+
* [`Result`](#result-)
72+
* [整数をパースする](#整数をパースする)
73+
* [`Result` 型エイリアスを用いたイディオム](#result-型エイリアスを用いたイディオム)
74+
* [小休止:アンラップは悪ではない](#小休止アンラップは悪ではない)
8175
* [複数のエラー型を扱う](#working-with-multiple-error-types)
82-
* [`Option``Result` で構成する](#composing-option-and-result)
76+
* [`Option``Result` を合成する](#composing-option-and-result)
8377
* [コンビネータの限界](#the-limits-of-combinators)
8478
* [早期のリターン](#early-returns)
8579
* [`try!` マクロ](#the-try-macro)
@@ -88,7 +82,7 @@ Rustでは戻り値を使います。
8882
* [`Error` トレイト](#the-error-trait)
8983
* [`From` トレイト](#the-from-trait)
9084
* [本当の `try!` マクロ](#the-real-try-macro)
91-
* [独自のエラー型で構成する](#composing-custom-error-types)
85+
* [独自のエラー型を合成する](#composing-custom-error-types)
9286
* [ライブラリ作者たちへのアドバイス](#advice-for-library-writers)
9387
* [ケーススタディ:人口データを読み込むプログラム](#case-study-a-program-to-read-population-data)
9488
* [最初のセットアップ](#initial-setup)
@@ -101,7 +95,6 @@ Rustでは戻り値を使います。
10195
* [簡単な説明(まとめ)](#the-short-story)
10296

10397
<!-- # The Basics -->
104-
<span id="the-basics"></span>
10598
# 基礎
10699

107100
<!-- You can think of error handling as using *case analysis* to determine whether -->
@@ -182,7 +175,6 @@ fn main() {
182175
でも彼は、途中にある、あらゆるものを蹴散らしてしまいます。
183176

184177
<!-- ## Unwrapping explained -->
185-
<span id="unwrapping-explained"></span>
186178
## アンラップ(unwrap) とは
187179

188180
<!-- In the previous example, we claimed -->
@@ -206,7 +198,6 @@ Rustでなにかを「アンラップする」時、こう言っているのと
206198
どちらの型にも `unwrap` という名前のメソッドが定義されています。
207199

208200
<!-- ### The `Option` type -->
209-
<span id="the-option-type"></span>
210201
### `Option`
211202

212203
<!-- The `Option` type is [defined in the standard library][5]: -->
@@ -332,8 +323,7 @@ impl<T> Option<T> {
332323
しかし残念なことに、そこにある `panic!` が意味するものは、`unwrap` が合成可能ではない、つまり、陶器店の中の雄牛だということです。
333324

334325
<!--- ### Composing `Option<T>` values -->
335-
<span id="composing-optiont-values"></span>
336-
### `Option<T>` 値で構成する
326+
### `Option<T>` 値を合成する
337327

338328
<!-- In an [example from before](#code-option-ex-string-find), -->
339329
<!-- we saw how to use `find` to discover the extension in a file name. Of course, -->
@@ -482,7 +472,7 @@ fn main() {
482472
<!-- need the file name which is typically extracted from a file *path*. While most -->
483473
<!-- file paths have a file name, not *all* of them do. For example, `.`, `..` or -->
484474
<!-- `/`. -->
485-
もうひとつ注目すべきコンビネータがあります。それは `and_then` です。これを使うと *不在の可能性* を考慮しながら、別々の処理を簡単に組み合わせることができます。
475+
もうひとつ特筆すべきコンビネータがあります。それは `and_then` です。これを使うと *不在の可能性* を考慮しながら、別々の処理を簡単に組み合わせることができます。
486476
例えば、この節のほとんどのコードは、与えられたファイル名について拡張子を見つけだします。
487477
そのためには、まずファイル *パス* から取り出したファイル名が必要です。
488478
大抵のパスにはファイル名がありますが、 *全て* がというわけではありません。
@@ -567,7 +557,6 @@ fn file_path_ext(file_path: &str) -> Option<&str> {
567557
`unwrap` のようなメソッドは、 `Option<T>``None` の時にパニックを起こすので、このような選択の機会を与えません。
568558

569559
<!-- ## The `Result` type -->
570-
<span id="the-result-type"></span>
571560
## `Result`
572561

573562
<!-- The `Result` type is also -->
@@ -605,7 +594,7 @@ type Option<T> = Result<T, ()>;
605594
<!-- the type and value level terms have the same notation!) -->
606595
これは `Result` の2番目の型パラメータを `()` (「ユニット」または「空タプル」と発音します)に固定したものです。
607596
`()` 型のただ一つの値は `()` です。
608-
(そうなんです。型レベルと値レベルの用語が、全く同じ表記法を持ちます!)
597+
(そうなんです。型レベルと値レベルの項が、全く同じ表記法を持ちます!)
609598

610599
<!-- The `Result` type is a way of representing one of two possible outcomes in a -->
611600
<!-- computation. By convention, one outcome is meant to be expected or “`Ok`” while -->
@@ -618,6 +607,7 @@ type Option<T> = Result<T, ()>;
618607
<!-- defined][7] -->
619608
<!-- in the standard library. Let's define it: -->
620609
`Option` と全く同じように、`Result` 型も標準ライブラリで [`unwrap` メソッドが定義されています][7]
610+
定義してみましょう:
621611

622612
```rust
623613
# enum Result<T, E> { Ok(T), Err(E) }
@@ -654,7 +644,6 @@ impl<T, E: ::std::fmt::Debug> Result<T, E> {
654644
では、例を見ていきましょう。
655645

656646
<!-- ### Parsing integers -->
657-
<span id="parsing-integers"></span>
658647
### 整数をパースする
659648

660649
<!-- The Rust standard library makes converting strings to integers dead simple. -->
@@ -737,7 +726,7 @@ impl str {
737726
この関数を同じように一般化することもできますが(そして、そうするべきでしょうが)、今は明快さを優先しましょう。
738727
`i32` だけを扱うことにしますので、それの [`FromStr` の実装がどうなっているか探しましょう](../std/primitive.i32.html)
739728
(ブラウザで `CTRL-F` を押して「FromStr」を探します。)
740-
そして [関連型associated type][10] から `Err` を見つけます。
729+
そして [関連型(associated type)][10] から `Err` を見つけます。
741730
こうすれば、具体的なエラー型が見つかります。
742731
この場合、それは [`std::num::ParseIntError`](../std/num/struct.ParseIntError.html) です。
743732
これでようやく関数を書き直せます:
@@ -800,7 +789,6 @@ fn main() {
800789
さらに `Result` は2つ目の型パラメータを取りますので、エラー型だけに影響を与える [`map_err`](../std/result/enum.Result.html#method.map_err)`map` に相当)と [`or_else`](../std/result/enum.Result.html#method.or_else)`and_then` に相当)もあります。
801790

802791
<!-- ### The `Result` type alias idiom -->
803-
<span id="the-result-type-alias-idiom"></span>
804792
### `Result` 型エイリアスを用いたイディオム
805793

806794
<!-- In the standard library, you may frequently see types like -->
@@ -846,7 +834,6 @@ fn double_number(number_str: &str) -> Result<i32> {
846834
それらは通常 `io::Result<T>` のように書かれ、`std::result` のプレーンな定義の代わりに `io` モジュールの型エイリアスを使っていることが、明確にわかるようになっています。
847835

848836
<!-- ## A brief interlude: unwrapping isn't evil -->
849-
<span id="a-brief-interlude-unwrapping-isnt-evil"></span>
850837
## 小休止:アンラップは悪ではない
851838

852839
<!-- If you've been following along, you might have noticed that I've taken a pretty -->
@@ -877,7 +864,7 @@ fn double_number(number_str: &str) -> Result<i32> {
877864
<!-- exposes a bug in your program. This can be explicit, like from an `assert!` -->
878865
<!-- failing, or it could be because your index into an array was out of bounds. -->
879866
* **パニックがプログラムのバグの兆候となる時。**
880-
コードの中の不変的な条件が、ある特定のケースの発生を未然に防ぐ時(例えば、空のスタックから取り出そうとしたなど)、パニックを起こしても差し支えありません。
867+
コードの中の不変条件が、ある特定のケースの発生を未然に防ぐ時(例えば、空のスタックから取り出そうとしたなど)、パニックを起こしても差し支えありません。
881868
なぜなら、そうすることでプログラムに潜むバグが明るみに出るからです。
882869
これは `assert!` の失敗のような明示的な要因によるものだったり、配列のインデックスが境界から外れたからだったりします。
883870

TranslationTable.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
| syntactic sugar | 糖衣構文
156156
| system | システム
157157
| tagged union | タグ付き共用体
158+
| term | 項
158159
| thread-locality | スレッドローカル性
159160
| threadsafe | スレッドセーフ
160161
| tick | クオート

0 commit comments

Comments
 (0)