Loading tutorials
Result and Option, and the habits the rest of this tutorial builds on.5 min readResult and Option are, you can read a match over them, and you can run a Cargo project. Here you will learn what unwrap and expect do, what a panic does to a program, and how to decide when a panic is the right choice. The next chapters build the ? oper6 min read? makes error handling short, you need to know what it replaces. This chapter covers the manual tools: match, if let, let ... else, and the methods on Result. They are still useful after you learn ?, because ? only covers the case where you want to return the error unchanged or 5 min read? operator replaces repetitive match blocks when a function should pass a failure up to its caller. It assumes you can write Rust functions and match expressions, know what Result<T, E> is (Ok or Err), and can build and run a Cargo project. Later chapters cover5 min readmatch expressions, know what Result<T, E> and Option<T> are, and have used ? in at least one function. It takes the operator apart so you can predict what it does, and why some uses fail to compile.5 min readResult, and that you know ? returns early on Err. It also assumes you know what the compiler's match-based expansion of ? looks like, and that you can implement a trait for a type. Here you will see how the From trait lets ? ch5 min readResult and Option work, how match works, and how ? behaves on a Result inside a function that returns Result. Here you will apply the same operator to Option, see where it differs, and learn the cases where the compiler rejects it.4 min readOption and Result. A lookup returns Option because "not found" is a normal outcome. The function that called it returns Result because "not found" is a failure there. This chapter shows how to convert between the two so that ? works across the boundary.5 min readmatch expressions and implement a trait for a type. It also assumes you know how ? returns early from a function that returns Result, and that ? converts errors through the From trait. Here you will use those pieces to build an error type for your own lib5 min readResult, use ? to propagate errors, and read a basic trait implementation. You should also know that ? converts the error with From before it returns. The previous chapter showed how to build a custom error enum. This chapter shows the 6 min readResult and use ? inside them. It also assumes you know what Box<dyn Error> is and have run a Cargo project. Here you will see how the error that ? produces at the top of a program becomes output and an exit code.5 min readResult and Option signatures and have used ? in simple functions. You should also know that ? converts errors with the From trait. Here you will learn to read the compiler errors that ? produces, fix each one, and recognize where ? stops being the righ5 min readmap and collect on iterators, and use ? inside functions that return Result. It also assumes you know what Result<T, E> and Option<T> look like. If ? is still new to you, review the earlier chapters first.5 min readResult, the ? operator, the From trait, hand-written custom error enums, and Box<dyn Error>. You also need to be able to add a dependency to Cargo.toml.5 min read