Result
Result
is similar to Option
, but indicates the success or failure of an operation, each with a different enum variant. It is generic: Result<T, E>
where T
is used in the Ok
variant and E
appears in the Err
variant.
Speaker Notes
This slide should take about 5 minutes.
Option
と同様に、成功した値はResult
の内部にあり、デベロッパーはそれを明示的に抽出する必要があります。これにより、エラーチェックが促進されます。エラーが発生してはならない場合は、unwrap()
またはexpect()
を呼び出すことができます。これもデベロッパーのインテントのシグナルです。Result
のドキュメントを読むことをすすめましょう。この講座では取り上げませんが、言及する価値があります。このドキュメントには、関数型プログラミングに役立つ便利なメソッドや関数が多数含まれています。Result
is the standard type to implement error handling as we will see on Day 4.