serde_hashkey

Trait FloatPolicy

Source
pub trait FloatPolicy: Sealed {
    type F32: FloatRepr<f32>;
    type F64: FloatRepr<f64>;
}
Expand description

A policy for handling floating point types in a Key.

Currently there are two important FloatPolicy types: RejectFloatPolicy and OrderedFloat. The former will emit errors instead of allowing floats to be serialized and the latter while serialize them and provide a total order which does not adhere to the IEEE standard.

§Examples

Example using a non-default float policy:

use serde_hashkey::{Key, Float, to_key_with_ordered_float, OrderedFloat, OrderedFloatPolicy};

let a: Key<OrderedFloatPolicy> = to_key_with_ordered_float(&42.42f32)?;
assert!(matches!(a, Key::Float(Float::F32(OrderedFloat(..)))));

let b: Key<OrderedFloatPolicy> = to_key_with_ordered_float(&42.42f64)?;
assert!(matches!(b, Key::Float(Float::F64(OrderedFloat(..)))));

Required Associated Types§

Source

type F32: FloatRepr<f32>

The type encapsulating a 32-bit float, or f32.

Source

type F64: FloatRepr<f64>

The type encapsulating a 64-bit float, or f64.

Implementors§