Use derive_more::{Display, Error} for error messages #39

Merged
AljoschaMeyer merged 2 commits from aecsocket/willow_rs:feat/derive-display into main 2026-04-07 17:38:36 +02:00
Contributor

Removes manual impl Display and impl Error blocks, replacing them with derive_more's (no_std compatible).

Massively reduces maintenance burden for implementing Display and Error on new error types!

Changes error messages to match the Rust API spec, from https://rust-lang.github.io/api-guidelines/interoperability.html?highlight=error#examples-of-error-messages:

The error message given by the Display representation of an error type should be lowercase without trailing punctuation, and typically concise.

This includes error messages and expect messages. Also added backticks around code elements in messages - nitpicky, but I'm precise.

Uses workspace.dependencies to share the derive_more dep between crates, can be changed to explicitly include the same dep in each subcrate tho.

You could use different crates like snafu, thiserror, etc. derive_more is my personal choice, since it includes a bunch more derivable traits, so it's nice for convenience if you want to derive more stuff later.

Removes manual `impl Display` and `impl Error` blocks, replacing them with `derive_more`'s (no_std compatible). Massively reduces maintenance burden for implementing Display and Error on new error types! Changes error messages to match the Rust API spec, from https://rust-lang.github.io/api-guidelines/interoperability.html?highlight=error#examples-of-error-messages: > The error message given by the Display representation of an error type should be lowercase without trailing punctuation, and typically concise. This includes error messages and `expect` messages. Also added backticks around code elements in messages - nitpicky, but I'm precise. Uses `workspace.dependencies` to share the `derive_more` dep between crates, can be changed to explicitly include the same dep in each subcrate tho. You could use different crates like snafu, thiserror, etc. derive_more is my personal choice, since it includes a bunch more derivable traits, so it's nice for convenience if you want to derive more stuff later.

Jup, this looks good, thank you.

I opened an issue over on bab_rs to do things the same way in that crate as well.

Jup, this looks good, thank you. I opened an issue over on [bab_rs](https://codeberg.org/worm-blossom/bab_rs/issues/21) to do things the same way in that crate as well.
Sign in to join this conversation.
No description provided.