hyperledger / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
432 stars 276 forks source link

`serde` validation hook in deserialize #1995

Open mversic opened 2 years ago

mversic commented 2 years ago

It is quite often that we need to write custom serde::Deserialize implementations just to validate structure's invariants. If possible, we should write some sort of a hook into serde macro system that would take validation function and generate deserialize implementation for a struct.

Also, maybe there is some crate offering this functionality or it can be done with serde.

mversic commented 2 years ago

this crate may be of some help

mversic commented 2 years ago

#[serde(try_from = "FromType")] annotation might be of great use for this purpose