yaml-edit 0.1.0

A lossless parser and editor for YAML files
Documentation
  • Coverage
  • 100%
    30 out of 30 items documented1 out of 5 items with examples
  • Size
  • Source code size: 16.41 MB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 8.63 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 28s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jelmer

Lossless YAML Parser and Editor

A Rust library for parsing and editing YAML files while preserving all whitespace, comments, and formatting. Built with the rowan library for lossless syntax trees.

Features

  • Lossless parsing: Preserves all whitespace, comments, and original formatting
  • Editing support: Modify YAML structures while maintaining formatting
  • Error recovery: Continues parsing even with syntax errors
  • Position tracking: Detailed error locations for debugging

Example

use yaml_edit::Yaml;
use std::str::FromStr;

let input = r#"
# Configuration file
name: my-project
version: 1.0.0

dependencies:
  - serde
  - tokio

features:
  default: []
  full:
    - "serde"
    - "tokio"
"#;

let mut yaml = Yaml::from_str(input).unwrap();

// Access documents
if let Some(doc) = yaml.document() {
    if let Some(mapping) = doc.as_mapping() {
        // Get values while preserving structure
        if let Some(name_node) = mapping.get("name") {
            println!("Project name: {}", name_node.text());
        }
    }
}

// The original formatting is preserved
println!("{}", yaml);