Closed kjeremy closed 7 years ago
In trying to deserialize:
#[derive(Debug, Deserialize)] struct NoisePower { value: f32, units: String } #[derive(Debug, Deserialize)] struct ReceiverReport { #[serde(rename = "NoisePower")] noise_power: NoisePower } #[test] fn receiver_noise_report_a() { let xml = r##" <!--<?xml version=”1.0” standalone=”yes”?>--> <ReceiverReport> <NoisePower value="-152.3" units="dBm"/> </ReceiverReport> "##; let report: ReceiverReport = deserialize(xml.as_bytes()).unwrap(); println!("{:#?}", report); }
I get:
'tests::receiver_noise_report_a' panicked at 'called Result::unwrap() on an Err value: invalid type: string "-152.3", expected f32', /checkout/src/libcore/result.rs:906:4
Result::unwrap()
Err
How do I ensure that NoisePower::value is deserialized as f32?
NoisePower::value
f32
Duplicate of #25
In trying to deserialize:
I get:
How do I ensure that
NoisePower::value
is deserialized asf32
?