serde-hashkey
Serde-based in-memory key serialization which supports hashing.
This allows any serde-serializable type to be converted into a value which
implements PartialEq
, Eq
, ParialOrd
, Ord
, and Hash
.
Key is useful because it allows for a form of type-erasure. Let's say you want to build a generic in-memory key-value store where you want to store arbitrary serde-serializable keys. This is useful for things like caches or dependency injection frameworks.
Usage
Add the following to your Cargo.toml:
[]
= "0.4.5"
Float policies
By default, Key can't include floating point types such as f32
and
f64
. Neither of these are totally ordered nor hashable.
To enable the Key type to use f32
and f64
it can be constructed with a
specific float policy.
Available float policies are:
- RejectFloatPolicy - the default behavior when using to_key.
- OrderedFloat - the behavior when using to_key_with_ordered_float. The
ordered-float
feature must be enabled to use this. The behavior is derived from theordered-float
crate.
Features
ordered-float
- Enables serializing floating point numbers through behavior derived from theordered-float
crate
Examples
You can run this example with
cargo run --example book
use HashMap;
use ;
use ;
let book = Book ;
let key = to_key?;
let mut ratings = new;
ratings.insert;
println!;
println!;
println!;