mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-14 11:41:01 +00:00
Unignore Serializer::serialize_unit_variant example
This commit is contained in:
+13
-2
@@ -421,13 +421,24 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, and the `variant` is the name of the
|
/// this variant within the enum, and the `variant` is the name of the
|
||||||
/// variant.
|
/// variant.
|
||||||
///
|
///
|
||||||
/// A reasonable implementation would be to forward to `serialize_unit`.
|
/// ```rust
|
||||||
|
/// # use serde::{Serialize, Serializer};
|
||||||
|
/// #
|
||||||
|
/// enum E {
|
||||||
|
/// A,
|
||||||
|
/// B,
|
||||||
|
/// }
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// impl Serialize for E {
|
||||||
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
/// where S: Serializer
|
||||||
|
/// {
|
||||||
/// match *self {
|
/// match *self {
|
||||||
/// E::A => serializer.serialize_unit_variant("E", 0, "A"),
|
/// E::A => serializer.serialize_unit_variant("E", 0, "A"),
|
||||||
/// E::B => serializer.serialize_unit_variant("E", 1, "B"),
|
/// E::B => serializer.serialize_unit_variant("E", 1, "B"),
|
||||||
/// }
|
/// }
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_unit_variant(self,
|
fn serialize_unit_variant(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
|
|||||||
Reference in New Issue
Block a user