-
Notifications
You must be signed in to change notification settings - Fork 231
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
Could impl_deserialize_for_internally_tagged_enum!
handle a default case?
#629
Comments
It is not clear for me what exactly you need. Perhaps this is already could be implemented using existing serde API. Could you provide an example of your Rust struct and XML that you want to map? |
Sorry for the confusion, let me try to explain this a bit better. <Root>
<SomeElement type="Specific">
<MoreSpecific>a</MoreSpecific>
<Common>123</Common>
</SomeElement>
<SomeElement type="AnotherType">
<Common>MaybeNotAnInt</Common>
</SomeElement>
<SomeElement type="YetAnotherType">
<Common>AnotherString</Common>
</SomeElement>
</Root> I could map to the following enum: enum Elements {
Specific({Common: u32, MoreSpecific: String}),
TheRest({Common: String})
} As of now, I deserialize to: struct CommonStructure {
r#type: String,
Common: String,
MoreSpecific: Option<String>
} and then I'd really like to use The idea is that I'd like "everything that's not I'm sorry I can't explain it better, but basically getting the equivalent of the |
Ah, I didn't immediately realize it was about macro quick-xml/src/serde_helpers.rs Lines 181 to 186 in 1be35e1
with Ok(deserialize_variant!(...)) with the name of default variant. Feel free to submit a PR!
|
impl_deserialize_for_internally_tagged_enum!
handle a default case?
Thanks for the detailed answer. Unfortunately I have never written a single macro, so it's probably gonna take a while for me to find the syntax to add an optional argument (so that it's backward compatible), and how to deal with this in the body macro. I'll try to, at some point, but can't promise I'll manage to 😅 Thanks again. |
Fixed in #634 |
Hello and thanks a lot for your work.
Would it be possible (and would it make sense) for
impl_deserialize_for_internally_tagged_enum
to handle a default case?Like "for every other value of this tag, just deserialise to this enum variant.
Not sure how common this is but I'm facing this exact pattern where I'd like to handle a few variants that I know are specific, and all the rest can just be fall into a generic struct.
I hope it's clear, sorry if it's already possible and I missed it. Happy to update the docs to highlight it in this case.
Thanks a lot.
The text was updated successfully, but these errors were encountered: