Id like to divide my_val
by 100 on deserialization:
#[derive(Debug, Deserialize, Clone)]
pub struct MyObject {
pub other: String,
pub my_val: f64, // <-- divide by 100.0
}
I found deserialize_with
but the only examples I could find is conversion from string into float
#[serde(deserialize_with = "my_val_division")]
pub my_val: f64,
and
fn my_val_division<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: Deserializer<'de>,
{
// what to do here?
}
How to do the division on deserialization?