Closed brunoczim closed 4 months ago
I would prefer not to build this into thiserror. I think it's just fine to handwrite the simple From
impl as you showed, or you can look for a more fully-featured derive(From)
library that could generate this kind of impl based on attributes.
I am facing this situation:
Which yields this error:
However, there is a pretty reasonable implementation of
From<tera::Error> for Error
: make this extra fieldpath
be constructed withNone
. Something like:I could implement it manually, but it feels like it's a work that the procedural macro could be doing. Not only in my situation, but also in many similar situations,
From
could be automatically implemented constructing extra fields with some given default values. I'd propose this API:And also, to improve ergonomics, if the default value is omitted from the attribute, the proc-macro could generate
Default::default()
as the constructed value. For instance, sinceNone == Default::default()
, the code above would be equivalent to the code below:I intend to implement this myself if I find some time to do it, but I need feedback first. Is this feature welcome? If I open a PR with this, would it be welcome?