I'm trying to implement a kind of user-extensible deserialization that allows you to "plug in" extra deserialize implementations. The basic idea is to have a Seed struct containing a HashMap<String, fn (&Seed, &mut erased_serde::Deserializer) -> erased_serde::Error> and use serde::DeserializeSeed to deserialize stuff. This is working pretty well, but there's an annoying issue with the error handling.
Whenever I call one of the deserialize implementations I can get an erased_serde::Error, but to bubble it up I need to convert it to an error for the deserializer I am using (serde_json at the moment, but I would like to remain generic), by using serde::de::Error::custom. These calls can be fairly recursive, so I might end up going back-and-forth between the two error types a few times. This is giving me error messages that look like this:
Error("trailing comma at line 32 column 41 at line 32 column 41 at line 33 column 37 at line 34 column 33 at line 35 column 29 at line 36 column 25 at line 36 column 25 at line 36 column 25 at line 36 column 25", line: 36, column: 25)
The ideal solution for me would be the ability to cast erased_serde::Error back to the original error type, by representing it as a Box<serde::de::Error>. I'm not sure whether my use-case is typical for this library so possibly this makes no sense in the general case, but I am interested to know what you think.
I'm trying to implement a kind of user-extensible deserialization that allows you to "plug in" extra deserialize implementations. The basic idea is to have a
Seedstruct containing aHashMap<String, fn (&Seed, &mut erased_serde::Deserializer) -> erased_serde::Error>and useserde::DeserializeSeedto deserialize stuff. This is working pretty well, but there's an annoying issue with the error handling.Whenever I call one of the deserialize implementations I can get an
erased_serde::Error, but to bubble it up I need to convert it to an error for the deserializer I am using (serde_jsonat the moment, but I would like to remain generic), by usingserde::de::Error::custom. These calls can be fairly recursive, so I might end up going back-and-forth between the two error types a few times. This is giving me error messages that look like this:Error("trailing comma at line 32 column 41 at line 32 column 41 at line 33 column 37 at line 34 column 33 at line 35 column 29 at line 36 column 25 at line 36 column 25 at line 36 column 25 at line 36 column 25", line: 36, column: 25)The ideal solution for me would be the ability to cast
erased_serde::Errorback to the original error type, by representing it as aBox<serde::de::Error>. I'm not sure whether my use-case is typical for this library so possibly this makes no sense in the general case, but I am interested to know what you think.