reem / rust-ordered-float

MIT License
221 stars 64 forks source link

OrderedFloat does not implement Deserialize #147

Closed ghproek closed 8 months ago

ghproek commented 8 months ago

I get an error saying that OrderedFloat doesn't implement Deserialize, but I think you can just do this with a macro, no? From the serde documentation:

use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    let serialized = serde_json::to_string(&point).unwrap();
    println!("serialized = {}", serialized);

    let deserialized: Point = serde_json::from_str(&serialized).unwrap();
    println!("deserialized = {:?}", deserialized);
}
mbrubeck commented 8 months ago

OrderedFloat implements Deserialize when the optional serde dependency is enabled:

https://github.com/reem/rust-ordered-float/blob/v4.2.0/src/lib.rs#L1882

To enable it, run cargo add ordered-float --features serde or add this to your Cargo.toml dependencies section:

ordered-float = { version = "4.2.0", features = ["serde"] }