serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
9.06k stars 767 forks source link

Propagate parse errors inside a flattened Option struct #2751

Open johnmave126 opened 4 months ago

johnmave126 commented 4 months ago

This is an attempt to address https://github.com/serde-rs/json/issues/644

The idea is to go through a proxy type OptionFlatMapDeserializer when calling deserialize_option in FlatMapDeserializer. Such proxy type provides a custom error type FlatStructError which only catches missing_field error during the immediate struct deserialization. All the errors happening nested will be preserved in another variant. In this way, we could propagate error inside a flattened struct.

I guess some more tests and comments are needed, but I want to put this work forward for preliminary test.