-
-
Notifications
You must be signed in to change notification settings - Fork 877
Description
Hello.
I have some data format for which I had implemented Deserializer. It has deserialize_struct, where I have if name == "SOME_STRUCT", then I calling visitor.visit_map() with very specific MapAccess.
All was perfectly fine, until I put this struct inside untagged enum.
My struct have Deserialize implementation, which calls deserializer.deserialize_struct("SOME_STRUCT", &["SOME_FIELDS"], MyVisitor). And as I see, serde does not try to call corresponding method in my deserializer, but uses deserialize_any and then sends first value which he found to MyVisitor. But this value is from my general MapAccess implementation, not custom one for SOME_STRUCT.
Is there some workarounds to fix this issue, or maybe possibility to implement some attribute to alter mechanic of untagged enum?
I'll try to describe my original problem, maybe it will give some context and we can to do something more useful than continue to complicate untagged enums.
I actually parsing yaml, but I need to be able report line:column of errors, and even if it was parsed successfully, I need to have line:column markers, because after parsing I processing parsed data and there still can be semantic errors, which I want to report too, pointing to specific lines/columns.
I found this solution in toml crate: https://docs.rs/toml/0.5.6/src/toml/spanned.rs.html#35-42 (which I think will fail too if you will put Spanned<String> inside a untagged enum) and made mine in this style.
But actually, I think that there should be possibility to access internals of specific Deserializer instance from Deserialize, or ability to ask him somehow to return specific type even if this type do not implements Deserialize. I'll be happy, if I there will be Deserializer method like inspect_custom(&self, name: &str) -> Result<*const sometype, Error>, which I can call from Deserialize implementation and unsafely do my dark deeds if I needed to and current deserializer supports it. Maybe it possible to make more clean with some traits, but nothing comes to mind.
Thanks.
UPD: took a look at the sources, looks like all of this is impossible for untagged/internally tagged enums because of deserialization to Content which erases all information that has specific Deserializer :(