Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #187 from dtolnay/multiser
Browse files Browse the repository at this point in the history
Support multi-doc serialization
  • Loading branch information
dtolnay committed Feb 2, 2021
2 parents b5da67e + aa2713e commit b16a401
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ser.rs
Expand Up @@ -9,6 +9,7 @@ use yaml_rust::{yaml, Yaml, YamlEmitter};

/// A structure for serializing Rust values into YAML.
pub struct Serializer<W> {
documents: usize,
writer: W,
}

Expand All @@ -18,7 +19,10 @@ where
{
/// Creates a new YAML serializer.
pub fn new(writer: W) -> Self {
Serializer { writer }
Serializer {
documents: 0,
writer,
}
}

/// Unwrap the underlying `io::Write` object from the `Serializer`.
Expand All @@ -27,6 +31,10 @@ where
}

fn write(&mut self, doc: Yaml) -> Result<()> {
if self.documents > 0 {
self.writer.write_all(b"...\n").map_err(error::io)?;
}
self.documents += 1;
let mut writer_adapter = FmtToIoWriter {
writer: &mut self.writer,
};
Expand Down

0 comments on commit b16a401

Please sign in to comment.