pub fn to_key_with_ordered_float<T>(
    value: &T
) -> Result<Key<OrderedFloatPolicy>, Error>where
    T: Serialize,
Available on crate feature ordered-float only.
Expand description

Serialize the given value to a Key using OrderedFloatPolicy.

This policy is derived from the OrderedFloat type in the ordered-float crate.

Examples

use serde_derive::{Deserialize, Serialize};
use serde_hashkey::{from_key, to_key_with_ordered_float, OrderedFloat, Key};
use std::collections::HashMap;

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Author {
    name: String,
    age: f32,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Book {
    title: String,
    author: Author,
}

let book = Book {
    title: String::from("Birds of a feather"),
    author: Author {
        name: String::from("Noah"),
        age: 42.5,
    },
};

let key = to_key_with_ordered_float(&book)?;
let book2 = from_key(&key)?;

assert_eq!(book, book2);