New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add serde attribute try_from
#1526
Conversation
Hmm... This will break serde's backward compatibility (1.13+) as try_from / try_into just stabilized 😢 Would it be acceptable to make it a feature? |
Would it be possible to make this feature conditionally available to versions that support |
@fanzeyi Hi! I'm not a maintainer, but looking at how the |
@davidbarsky Let me ask @dtolnay today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this implementation looks good to me. We use a build script to provide things like this only on compilers that support them, without needing a feature -- see f249e72.
Ah, my bad for misunderstanding. Thanks for the clarification! |
@dtolnay Slightly odd request, but would it be possible to allow a custom If it's not possible, I suppose I could write out what is currently derived. I presume it isn't too common to do this, though. Edit: Actually, it looks simple enough to forward this manually that it probably isn't necessary to do this. |
This pull request adds a new serde attribute
try_from
which will make serde try to convert the type specified in the attribute to the type serde is trying to deserialize into. (#1524)For example,
will produce the following output:
Details
serde_derive
will generate thetry_from
call when generating deserializing codeserde::Error::custom
from
attribute,try_from
is incompatible withtransparent
from
andtry_from
attributes cannot be specified at the same time