Add support for custom error type for FromStr derive#494
Add support for custom error type for FromStr derive#494tyranron merged 16 commits intoJelteF:masterfrom
Conversation
2e88556 to
3f205f5
Compare
3f205f5 to
a70038a
Compare
a70038a to
d9109bc
Compare
There was a problem hiding this comment.
@kiendang sorry for some late feedback on this. Been quite busy lately. The implementation is quite nice, not mentioning several bikesheddings. Thank you for the great job!
Before merging this, however, I would like to approve the design with @JelteF.
|
@tyranron no worries. I do understand that's the nature of open source/volunteer work. Thanks for maintaining the library. |
bed4972 to
38d1ca4
Compare
ba0ea1c to
c9e2a5f
Compare
c9e2a5f to
6171c02
Compare
Co-authored-by: Jelte Fennema-Nio <github-tech@jeltef.nl>
3401a05 to
55b14c3
Compare
tyranron
left a comment
There was a problem hiding this comment.
@kiendang thanks for such a nice PR and for all the effort!
I've bikeshedded a little bit the code, and also tried to add support for syn::ExprCall and syn::ExprClosure. However, the later requires syn/full feature to be enabled, which requires some other disputable workarounds in derive_more, so I'll dissect them into a separate PR.
|
Thank you for the thorough review! |
Resolves #112
Related to #396
Synopsis
Add support for a
#[from_str(error(error_ty[, error_fn]))]attribute to specify a custom error type forFromStrderive for enums (or structs with no fields) in case where the string does not match any variant. A conversion function to convert aderive_more::FromStrErrorto the custom error type might optionally be provided. Otherwise the custom error typeTmust satisfyderive_more::FromStrError: Into<T>.strumprovides similar functionality. See Peternator7/strum#380.This approach could be used to set a custom error type for
TryIntoderive as well (#396).Solution
Checklist