diff --git a/serde/src/ser/mod.rs b/serde/src/ser/mod.rs index 1eaae172..31fbb748 100644 --- a/serde/src/ser/mod.rs +++ b/serde/src/ser/mod.rs @@ -777,6 +777,20 @@ pub trait Serializer: Sized { /// Serialize a unit struct like `struct Unit` or `PhantomData`. /// /// A reasonable implementation would be to forward to `serialize_unit`. + /// + /// ```rust + /// use serde::{Serialize, Serializer}; + /// + /// struct Nothing; + /// + /// impl Serialize for Nothing { + /// fn serialize(&self, serializer: S) -> Result + /// where S: Serializer + /// { + /// serializer.serialize_unit_struct("Nothing") + /// } + /// } + /// ``` fn serialize_unit_struct(self, name: &'static str) -> Result; /// Serialize a unit variant like `E::A` in `enum E { A, B }`.