You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A little background, I'm trying to make toml work with one of the enum I have (toml does not work with enums). I discovered the serde(into = "type", from = "type") attributes, and it works perfectly with my case. However, I do want to have the ability to handle unexpected input when serializing/de-serializing the enum.
I think it would be nice if serde could support a similar attribute try_into and try_from. An example could be:
One complication of supporting try_into and try_from is error handling. I'm not familiar with implementing serializer and deserializer with serde but I saw there is Error::Message in the example of implementing a data format. I wonder if it possible to have the user to return a String error message and passed that to the actual seralizer/deserializer etc.
Please let me know what do you think about this idea. Thanks!
The text was updated successfully, but these errors were encountered:
fanzeyi
changed the title
Support for TryFrom / TryInto
Feature Request: Support for [serde(try_into = "type", try_from = "type")]May 12, 2019
I would accept a PR for a try_from attribute. I would prefer not to do try_into yet until someone justifies a use case for it. The existing into attribute is already sort of confusing with the way it needs to clone self.
A little background, I'm trying to make toml work with one of the enum I have (
toml
does not work with enums). I discovered theserde(into = "type", from = "type")
attributes, and it works perfectly with my case. However, I do want to have the ability to handle unexpected input when serializing/de-serializing the enum.I think it would be nice if serde could support a similar attribute
try_into
andtry_from
. An example could be:One complication of supporting
try_into
andtry_from
is error handling. I'm not familiar with implementing serializer and deserializer with serde but I saw there isError::Message
in the example of implementing a data format. I wonder if it possible to have the user to return a String error message and passed that to the actual seralizer/deserializer etc.Please let me know what do you think about this idea. Thanks!
The text was updated successfully, but these errors were encountered: