Use anyhow for top-level error handling in binaries and thiserror for defining custom error types in libraries. anyhow provides a flexible Result<T, anyhow::Error> that erases error types, while thiserror generates impl std::error::Error for your custom structs via the #[derive(thiserror::Error)] macro. In the mdbook-trpl project, anyhow is used for the Result type in functions like rewrite_figure, while thiserror defines the CompositeError and Error structs in src/lib.rs and src/config/mod.rs.
What is the difference between anyhow and thiserror
anyhow handles errors in binaries with erased types, while thiserror defines custom error types for libraries.