mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-12 19:01:02 +00:00
Unignore Serializer::serialize_tuple_variant example
This commit is contained in:
+28
-7
@@ -645,13 +645,34 @@ pub trait Serializer: Sized {
|
|||||||
/// this variant within the enum, the `variant` is the name of the variant,
|
/// this variant within the enum, the `variant` is the name of the variant,
|
||||||
/// and the `len` is the number of data fields that will be serialized.
|
/// and the `len` is the number of data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
/// match *self {
|
/// use serde::{Serialize, Serializer};
|
||||||
/// E::T(ref a, ref b) => {
|
/// use serde::ser::SerializeTupleVariant;
|
||||||
/// let mut tv = serializer.serialize_tuple_variant("E", 0, "T", 2)?;
|
///
|
||||||
/// tv.serialize_field(a)?;
|
/// enum E {
|
||||||
/// tv.serialize_field(b)?;
|
/// T(u8, u8),
|
||||||
/// tv.end()
|
/// U(String, u32, u32),
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// impl Serialize for E {
|
||||||
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
/// where S: Serializer
|
||||||
|
/// {
|
||||||
|
/// match *self {
|
||||||
|
/// E::T(ref a, ref b) => {
|
||||||
|
/// let mut tv = serializer.serialize_tuple_variant("E", 0, "T", 2)?;
|
||||||
|
/// tv.serialize_field(a)?;
|
||||||
|
/// tv.serialize_field(b)?;
|
||||||
|
/// tv.end()
|
||||||
|
/// }
|
||||||
|
/// E::U(ref a, ref b, ref c) => {
|
||||||
|
/// let mut tv = serializer.serialize_tuple_variant("E", 1, "U", 3)?;
|
||||||
|
/// tv.serialize_field(a)?;
|
||||||
|
/// tv.serialize_field(b)?;
|
||||||
|
/// tv.serialize_field(c)?;
|
||||||
|
/// tv.end()
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|||||||
Reference in New Issue
Block a user