Closed QuietMisdreavus closed 4 years ago
I had an idea about the error-message problem and posted a new commit. It adds two new functions to types that deserialize via round_trip!
: twitter_deser_error
and roundtrip_deser_error
. They both attempt to deserialize into the inner types of SerEnum
, and reports the error that comes out, if any. It's not a perfect solution, but should allow for some kind of error reporting when combined with the raw
module. I'm not sure how to make it so that these can be called from the actual deserialization process, but it's at least something.
Closes #90
This PR adds a
Serialize
impl for various types in the library, most notablyTweet
andTwitterUser
. Since those types have existingDeserialize
impls that load via a "raw" type that mirrors Twitter's JSON representation, i needed to introduce a new mechanism to allow loading via either Twitter's JSON or egg-mode's.The way i did this for this PR was to introduce a new
round_trip!
macro that wrapped the structs and added some new items used internally by the macro:SerCopy
, a field-for-field copy of the given type,SerEnum
, an enum which can either be the "raw" type orSerCopy
,Deserialize
implementations that leverage the#[serde(untagged)]
attribute to drive the deserialization.One major drawback with this approach is that if the "raw" type gets out-of-sync with Twitter's representation, the only error message you see is
"data did not match any variant of untagged enum SerEnum"
, instead of knowing which field is missing. On the other hand, doing it this way means that there is no overhead of doing the deserialization manually (anyone remember the originalFromJson
impls?) or loading the whole response into aserde_json::Value
first. I'm posting this provisionally to see if this suits people's purposes, and to ask whether this should wrap other public types in egg-mode.