Loading tutorials
Option and Result, know what a trait and a derive attribute are, and can add a dependency with Cargo. The chapter reviews how Result and ? work, because the rest of the tutorial buil2 min readResult and Option, traits and #[derive], and how to add a dependency with Cargo. It covers the three traits that make a type usable as an error. The next chapter builds a full custom error type on them.3 min readmatch, Result, and traits. You should also know how ? returns early from a function. Here you build an error type with only the standard library. Doing it once by hand shows what thiserror generates for you in the next chapter.2 min readError trait, the hand-written ConfigError with its Display, Error and From impls, and how to add a dependency with Cargo.2 min readResult, the ? operator, and the basics of thiserror from the previous chapter. You should also know how to add a crate with Cargo.2 min readResult, the ? operator, enums, and traits. You should also have seen a hand-written error type and the thiserror derive from earlier chapters. Here you will meet anyhow, the crate most Rust binaries use for error handling.3 min readResult, the ? operator, and the basics of anyhow::Result from the previous chapter. You should also be able to add a crate with Cargo.2 min readResult and the ? operator, and that you have seen anyhow::Result and Context in the previous chapters. Sometimes a failure has no underlying error to wrap. A value is out of range, or a rule is broken. Three macros in anyhow cover these cases without a custom 2 min readResult and ?, derive traits, and add crates with Cargo. You have already seen thiserror generate error types and anyhow wrap any error. Now you will decide which one to use and where.3 min readthiserror, use #[from] and #[source], and add context with anyhow. Here you will see how to read the whole chain of causes and print it in a form that helps a user or a log reader.2 min readthiserror enum and return anyhow::Result from a function. It also assumes you know how .context(...) adds a message.2 min readthiserror enum and use ? to convert errors, as covered in the earlier chapters. It also assumes you know how #[test] functions and cargo test work.2 min readthiserror enum, use #[from] and #[source], and know when a library should use thiserror and an application anyhow. The focus here is how to keep an error type usable as the crate grows and as other code starts to depend on it.3 min read