Example for serialize_unit_struct

This commit is contained in:
David Tolnay 2017-04-13 15:20:01 -07:00
parent 385f83a7de
commit 2afbffa924
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -777,6 +777,20 @@ pub trait Serializer: Sized {
/// Serialize a unit struct like `struct Unit` or `PhantomData<T>`.
///
/// A reasonable implementation would be to forward to `serialize_unit`.
///
/// ```rust
/// use serde::{Serialize, Serializer};
///
/// struct Nothing;
///
/// impl Serialize for Nothing {
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
/// where S: Serializer
/// {
/// serializer.serialize_unit_struct("Nothing")
/// }
/// }
/// ```
fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error>;
/// Serialize a unit variant like `E::A` in `enum E { A, B }`.