[][src]Trait serde_hashkey::FloatPolicy

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

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(..)))));

Associated Types

type F32: FloatRepr<f32>[src]

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

type F64: FloatRepr<f64>[src]

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

Loading content...

Implementors

impl FloatPolicy for OrderedFloatPolicy[src]

impl FloatPolicy for RejectFloatPolicy[src]

Loading content...