dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
965 stars 165 forks source link

Support multi-doc serialization #187

Closed dtolnay closed 3 years ago

dtolnay commented 3 years ago
use anyhow::Result;
use serde::Serialize;
use std::collections::BTreeMap;

fn main() -> Result<()> {
    let mut buffer = Vec::new();
    let mut ser = serde_yaml::Serializer::new(&mut buffer);

    let mut object = BTreeMap::new();
    object.insert("k", 107);
    object.serialize(&mut ser)?;

    object.insert("j", 106);
    object.serialize(&mut ser)?;

    assert_eq!(buffer, b"---\nk: 107\n...\n---\nj: 106\nk: 107\n");
    Ok(())
}