dtolnay / dtolnay/thiserror

Allow extra fields when using #[from] (using Default trait)

Open
#441 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Rust
Stars
5.5k
Forks
213
PR merge metrics
No merged PRs in 30d

Description

It would be useful to allow extra fields in the structs when using `#[from]`, to optionally add additional context. I think that could be achieved by simply initializing them with `Default::default()` in the `From` implementation, and allowing user to add the context to errors later (e.g. with another `derive` macro from a different crate).

I could provide a PR that implement it, but I saw from some previous issues that you're somewhat against the idea of supporting adding context to the errors, so I want to make sure you're on board with this before I spend more time on it.

I believe that my proposal is minimally intrusive, and maintains the spirit of simplicity of this crate. If this would stray too much from the current interface, how about adding optional parameter to `#[from]`, e.g. `#[from(with_defaults)]`, that would trigger this behavior?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.