dtolnay / serde-yaml

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

Add a Serializer #186

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)?;

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

Closes #44.