2

I wish to deserialize the below struct, but using the new constructor to validate the deserialized fields:

#[derive(Deserialize)]
pub struct Timestamp {
    values: Vec<u32>,
}

impl Timestamp {
    pub fn new(values: Vec<u32>) -> Timestamp {
        // some quality check
        Timestamp { values: values }
    }
}

Is there an easy way to do that? I looked into writing a custom Deserializer, but I hoped that there would be an easier and less verbose way to do that.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
ced73
  • 21
  • 1
  • 1
    @SvenMarnach wow, usually I don't miss key things like that. Thanks! – Shepmaster Jun 21 '19 at 20:28
  • 1
    The [duplicate applied to your question](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9f59c0bcd780fff3b5b4fa161eb348f0). – Shepmaster Jun 21 '19 at 20:32

0 Answers0