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

Support multi-doc serialization #187

Merged
merged 1 commit into from Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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