Loading tutorials
Result type and the ? operator. This chapter reviews how they work and shows where they stop being enough. By the end you will know exactly what ? does when it meets an error. Custom error types and the From trait both depend o5 min readResult with the ? operator. You do not need thiserror or anyhow yet. Both crates generate code for the traits covered here, so you should know what that code does.6 min readmatch, Result, the ? operator, and implementing traits.6 min readResult and the ? operator, and you have seen the hand-written error type from the previous chapter. You should also be comfortable with #[derive(...)] and with adding a crate using Cargo.5 min read? in a function that returns Result, and add a crate with Cargo. It also assumes you know the thiserror basics from the previous chapter: #[derive(Error)] and #[error("...")]. Here you will learn how to make your error type hold the lower6 min readResult-returning function and use ?. It also assumes you have seen a hand-written or thiserror error enum, as in the previous chapters. Here you will learn what anyhow::Error is, why ? works with it, how it prints, and where it stops being the right cho5 min readResult-returning functions, use ?, and have anyhow in your Cargo.toml (cargo add anyhow). It also assumes you know that an error can have a source(), as covered in the chapters on the Error trait and #[from]/#[source].5 min readanyhow::Result, use ? to propagate errors, and attach messages with Context. It covers the three macros that create new anyhow errors when no underlying error exists yet.5 min readResult and ?, derive traits, and add crates with Cargo. It also assumes you have seen #[derive(Error)] from thiserror and anyhow::Result from anyhow, both covered in earlier ch6 min readthiserror enum with #[from] and #[source], and that you have used anyhow::Result and .context(...). Those topics come earlier in the tutorial. Here the focus is on reading an error after it has been built: walking its causes and deciding what to print.5 min readthiserror enum, return anyhow::Result from application code, and add context with Context. Earlier chapters covered those. Here you learn how to get a concrete error type back out of an anyhow::Error, and when you should not.5 min readResult has two contracts: the value it gives on success and the error it gives on failure. Many test suites check only the first. This chapter covers how to test the second, using the ConfigError type from earlier chapters.5 min read