serde-rs / serde-rs.github.io

https://serde.rs
Creative Commons Attribution Share Alike 4.0 International
22 stars 96 forks source link

Add an example for arbitrary type validation upon deserialization. #148

Open nathan-at-least opened 1 year ago

nathan-at-least commented 1 year ago

This adds an example for a useful pattern where a type needs to be validated arbitrarily (via TryFrom on an inner type) during deserialization. This comes directly from https://github.com/serde-rs/serde/issues/642#issuecomment-683276351 where I learned the pattern.

I couldn't figure out on my own how to do this via browsing https://serde.rs, so I went to the issue tracker where I found this recipe, so it seems like a good candidate for the examples section.

cschramm commented 1 year ago

I think this is pretty useful, but it might be worth mentioning https://github.com/serde-rs/serde/issues/2178 as a limitation.