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.