google / comprehensive-rust

This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.

Home Page:https://google.github.io/comprehensive-rust/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error-handling crates slide should be split

fw-immunant opened this issue · comments

We used to (in v1) separately show using thiserror (to remove the tedium of manually writing boilerplate From and Display implementations for custom error enums) and anyhow (to flatten error types and allow adding context to errors). Now we show them together, and it makes it harder to understand the value proposition of thiserror. In particular, the example does not demonstrate the #[from] attribute anymore and loses the ability to dispatch on error enums because it uses the erased anyhow::Result type.

We should split this slide back into two slides again so that we can separately address these separate concerns. thiserror provides convenience without changing semantics, while anyhow changes error semantics in a way that is mostly suitable for applications but not libraries.

This sounds like a good idea!