diff --git a/README.rst b/README.rst index a250092d1b..3792afe3c3 100644 --- a/README.rst +++ b/README.rst @@ -116,6 +116,8 @@ Recent Changes - Implemented ``Debug`` for ``map::{Entry, IntoIter, Iter, Keys, Values}`` and ``set::{Difference, Intersection, IntoIter, Iter, SymmetricDifference, Union}`` + - Serde trait ``IntoDeserializer`` are implemented for ``IndexMap`` and ``IndexSet``. + - 1.0.2 - The new methods ``IndexMap::insert_full`` and ``IndexSet::insert_full`` are diff --git a/src/serde.rs b/src/serde.rs index bd082a7c31..eb54e01f44 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -2,7 +2,8 @@ extern crate serde; use self::serde::ser::{Serialize, Serializer, SerializeMap, SerializeSeq}; -use self::serde::de::{Deserialize, Deserializer, MapAccess, SeqAccess, Visitor}; +use self::serde::de::{Deserialize, Deserializer, Error, IntoDeserializer, MapAccess, SeqAccess, Visitor}; +use self::serde::de::value::{MapDeserializer, SeqDeserializer}; use std::fmt::{self, Formatter}; use std::hash::{BuildHasher, Hash}; @@ -66,6 +67,19 @@ impl<'de, K, V, S> Deserialize<'de> for IndexMap } } +impl<'de, K, V, S, E> IntoDeserializer<'de, E> for IndexMap + where K: IntoDeserializer<'de, E> + Eq + Hash, + V: IntoDeserializer<'de, E>, + S: BuildHasher, + E: Error, +{ + type Deserializer = MapDeserializer<'de, ::IntoIter, E>; + + fn into_deserializer(self) -> Self::Deserializer { + MapDeserializer::new(self.into_iter()) + } +} + use IndexSet; @@ -121,3 +135,15 @@ impl<'de, T, S> Deserialize<'de> for IndexSet deserializer.deserialize_seq(OrderSetVisitor(PhantomData)) } } + +impl<'de, T, S, E> IntoDeserializer<'de, E> for IndexSet + where T: IntoDeserializer<'de, E> + Eq + Hash, + S: BuildHasher, + E: Error, +{ + type Deserializer = SeqDeserializer<::IntoIter, E>; + + fn into_deserializer(self) -> Self::Deserializer { + SeqDeserializer::new(self.into_iter()) + } +}