mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 06:41:03 +00:00
Unignore Serializer::serialize_struct example
This commit is contained in:
+21
-6
@@ -736,12 +736,27 @@ pub trait Serializer: Sized {
|
|||||||
/// The `name` is the name of the struct and the `len` is the number of
|
/// The `name` is the name of the struct and the `len` is the number of
|
||||||
/// data fields that will be serialized.
|
/// data fields that will be serialized.
|
||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust
|
||||||
/// let mut struc = serializer.serialize_struct("Rgb", 3)?;
|
/// use serde::{Serialize, Serializer};
|
||||||
/// struc.serialize_field("r", &self.r)?;
|
/// use serde::ser::SerializeStruct;
|
||||||
/// struc.serialize_field("g", &self.g)?;
|
///
|
||||||
/// struc.serialize_field("b", &self.b)?;
|
/// struct Rgb {
|
||||||
/// struc.end()
|
/// r: u8,
|
||||||
|
/// g: u8,
|
||||||
|
/// b: u8,
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// impl Serialize for Rgb {
|
||||||
|
/// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
/// where S: Serializer
|
||||||
|
/// {
|
||||||
|
/// let mut rgb = serializer.serialize_struct("Rgb", 3)?;
|
||||||
|
/// rgb.serialize_field("r", &self.r)?;
|
||||||
|
/// rgb.serialize_field("g", &self.g)?;
|
||||||
|
/// rgb.serialize_field("b", &self.b)?;
|
||||||
|
/// rgb.end()
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
fn serialize_struct(self,
|
fn serialize_struct(self,
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
|
|||||||
Reference in New Issue
Block a user