diff --git a/src/serde_seq.rs b/src/serde_seq.rs index d326a02e..fc3df6f2 100644 --- a/src/serde_seq.rs +++ b/src/serde_seq.rs @@ -28,6 +28,42 @@ use core::hash::{BuildHasher, Hash}; use core::marker::PhantomData; use crate::IndexMap; +use crate::map::Slice as MapSlice; +use crate::set::Slice as SetSlice; + +/// Serializes a `map::Slice` as an ordered sequence. +/// +/// This behaves like [`crate::serde_seq`] for `IndexMap`, serializing a sequence +/// of `(key, value)` pairs, rather than as a map that might not preserver order. +/// +/// Requires crate feature `"serde"` or `"serde-1"` +impl Serialize for MapSlice +where + K: Serialize, + V: Serialize, +{ + fn serialize(&self, serializer: T) -> Result + where + T: Serializer, + { + serializer.collect_seq(self) + } +} + +/// Serializes a `set::Slice` as an ordered sequence. +/// +/// Requires crate feature `"serde"` or `"serde-1"` +impl Serialize for SetSlice +where + T: Serialize, +{ + fn serialize(&self, serializer: Se) -> Result + where + Se: Serializer, + { + serializer.collect_seq(self) + } +} /// Serializes an `IndexMap` as an ordered sequence. ///