pub fn to_key<T>(value: &T) -> Result<Key<RejectFloatPolicy>, Error>where
T: Serialize,
Expand description
Serialize the given value to a Key.
ยงExamples
use serde_derive::{Deserialize, Serialize};
use serde_hashkey::{from_key, to_key, Key};
use std::collections::HashMap;
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Author {
name: String,
age: u32,
}
#[derive(Debug, PartialEq, Eq, 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,
},
};
let key = to_key(&book)?;
let book2 = from_key(&key)?;
assert_eq!(book, book2);