Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't deserialize f32 #46

Closed
kjeremy opened this issue Sep 8, 2017 · 1 comment
Closed

Can't deserialize f32 #46

kjeremy opened this issue Sep 8, 2017 · 1 comment

Comments

@kjeremy
Copy link

kjeremy commented Sep 8, 2017

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

How do I ensure that NoisePower::value is deserialized as f32?

@kjeremy
Copy link
Author

kjeremy commented Sep 8, 2017

Duplicate of #25

@kjeremy kjeremy closed this as completed Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant