Enum serde_hashkey::Key
source · [−]pub enum Key<F = RejectFloatPolicy>where
F: FloatPolicy,{
Unit,
Bool(bool),
Integer(Integer),
Float(Float<F>),
Bytes(Box<[u8]>),
String(Box<str>),
Seq(Box<[Key<F>]>),
Map(Box<[(Key<F>, Key<F>)]>),
}Expand description
The central key type, which is an in-memory representation of all supported serde-serialized values.
This can be serialized to a type implementing serde::Deserialize using from_key, and deserialized from a type implementing serde::Serialize using to_key. See the corresponding function for documentation.
The type parameter F corresponds to the FloatPolicy in used. It defaults
to RejectFloatPolicy which will cause floats to be rejected.
Examples
use serde_derive::{Deserialize, Serialize};
use serde_hashkey::{to_key, to_key_with_ordered_float};
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
struct Author {
name: String,
age: u32,
}
let key = to_key(&Author {
name: String::from("Jane Doe"),
age: 42,
})?;
// Note: serializing floats will fail under the default policy, but succeed
// under one supporting floats.
assert!(to_key(&42.0f32).is_err());
assert!(to_key_with_ordered_float(&42.0f32).is_ok());Variants
Unit
A unit value.
Bool(bool)
A boolean value.
Integer(Integer)
An integer.
Float(Float<F>)
A 32-bit floating-point number.
Bytes(Box<[u8]>)
A byte array.
String(Box<str>)
A string.
Seq(Box<[Key<F>]>)
A vector.
Map(Box<[(Key<F>, Key<F>)]>)
A map.
Implementations
Trait Implementations
sourceimpl<F: Clone> Clone for Key<F>where
F: FloatPolicy,
impl<F: Clone> Clone for Key<F>where
F: FloatPolicy,
sourceimpl<F: Debug> Debug for Key<F>where
F: FloatPolicy,
impl<F: Debug> Debug for Key<F>where
F: FloatPolicy,
sourceimpl<'de, F> Deserialize<'de> for Key<F>where
F: FloatPolicy,
impl<'de, F> Deserialize<'de> for Key<F>where
F: FloatPolicy,
Deserialize implementation for a Key.
This allows keys to be serialized immediately.
Examples
use serde_derive::Deserialize;
use serde_hashkey::{Key, OrderedFloatPolicy};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize)]
struct Foo {
key: Key<OrderedFloatPolicy>,
}
let foo: Foo = serde_json::from_str("{\"key\": 42.42}")?;
assert!(matches!(foo.key, Key::Float(..)));
Ok(())sourcefn deserialize<D>(deserializer: D) -> Result<Key<F>, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Key<F>, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<F> From<String> for Key<F>where
F: FloatPolicy,
impl<F> From<String> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<bool> for Key<F>where
F: FloatPolicy,
impl<F> From<bool> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<i128> for Key<F>where
F: FloatPolicy,
impl<F> From<i128> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<i16> for Key<F>where
F: FloatPolicy,
impl<F> From<i16> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<i32> for Key<F>where
F: FloatPolicy,
impl<F> From<i32> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<i64> for Key<F>where
F: FloatPolicy,
impl<F> From<i64> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<i8> for Key<F>where
F: FloatPolicy,
impl<F> From<i8> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<u128> for Key<F>where
F: FloatPolicy,
impl<F> From<u128> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<u16> for Key<F>where
F: FloatPolicy,
impl<F> From<u16> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<u32> for Key<F>where
F: FloatPolicy,
impl<F> From<u32> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<u64> for Key<F>where
F: FloatPolicy,
impl<F> From<u64> for Key<F>where
F: FloatPolicy,
sourceimpl<F> From<u8> for Key<F>where
F: FloatPolicy,
impl<F> From<u8> for Key<F>where
F: FloatPolicy,
sourceimpl<F: Hash> Hash for Key<F>where
F: FloatPolicy,
impl<F: Hash> Hash for Key<F>where
F: FloatPolicy,
sourceimpl<'de, F> IntoDeserializer<'de, Error> for &'de Key<F>where
F: FloatPolicy,
impl<'de, F> IntoDeserializer<'de, Error> for &'de Key<F>where
F: FloatPolicy,
type Deserializer = Deserializer<'de, F>
type Deserializer = Deserializer<'de, F>
The type of the deserializer being converted into.
sourcefn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
Convert this value into a deserializer.
sourceimpl<F: Ord> Ord for Key<F>where
F: FloatPolicy,
impl<F: Ord> Ord for Key<F>where
F: FloatPolicy,
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<F: PartialEq> PartialEq<Key<F>> for Key<F>where
F: FloatPolicy,
impl<F: PartialEq> PartialEq<Key<F>> for Key<F>where
F: FloatPolicy,
sourceimpl<F: PartialOrd> PartialOrd<Key<F>> for Key<F>where
F: FloatPolicy,
impl<F: PartialOrd> PartialOrd<Key<F>> for Key<F>where
F: FloatPolicy,
sourcefn partial_cmp(&self, other: &Key<F>) -> Option<Ordering>
fn partial_cmp(&self, other: &Key<F>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read moresourceimpl<F> Serialize for Key<F>where
F: FloatPolicy,
impl<F> Serialize for Key<F>where
F: FloatPolicy,
Serialize implementation for a Key.
This allows keys to be serialized immediately.
Examples
use serde_derive::Serialize;
use serde_hashkey::{Key, OrderedFloatPolicy, OrderedFloat, Float};
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
struct Foo {
key: Key<OrderedFloatPolicy>,
}
let foo: String = serde_json::to_string(&Foo { key: Key::Float(Float::F64(OrderedFloat(42.42f64))) })?;
assert_eq!(foo, "{\"key\":42.42}");
Ok(())impl<F: Eq> Eq for Key<F>where
F: FloatPolicy,
impl<F> StructuralEq for Key<F>where
F: FloatPolicy,
impl<F> StructuralPartialEq for Key<F>where
F: FloatPolicy,
Auto Trait Implementations
impl<F> RefUnwindSafe for Key<F>where
<F as FloatPolicy>::F32: RefUnwindSafe,
<F as FloatPolicy>::F64: RefUnwindSafe,
impl<F> Send for Key<F>where
<F as FloatPolicy>::F32: Send,
<F as FloatPolicy>::F64: Send,
impl<F> Sync for Key<F>where
<F as FloatPolicy>::F32: Sync,
<F as FloatPolicy>::F64: Sync,
impl<F> Unpin for Key<F>where
<F as FloatPolicy>::F32: Unpin,
<F as FloatPolicy>::F64: Unpin,
impl<F> UnwindSafe for Key<F>where
<F as FloatPolicy>::F32: UnwindSafe,
<F as FloatPolicy>::F64: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more