diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index d6ee65ae..189cf766 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -917,6 +917,24 @@ pub trait Serializer: Sized { /// using [`serialize_map`]. Implementors should not need to override this /// method. /// + /// ```rust + /// use std::collections::BTreeSet; + /// use serde::{Serialize, Serializer}; + /// + /// struct MapToUnit { + /// keys: BTreeSet, + /// } + /// + /// // Serializes as a map in which the values are all unit. + /// impl Serialize for MapToUnit { + /// fn serialize(&self, serializer: S) -> Result + /// where S: Serializer + /// { + /// serializer.collect_map(self.keys.iter().map(|k| (k, ()))) + /// } + /// } + /// ``` + /// /// [`serialize_map`]: #tymethod.serialize_map fn collect_map(self, iter: I) -> Result where