yaml-rust2

A fully YAML 1.2 compliant YAML parser and emitter written in pure Rust.

Library
Cargo
v0.12.0
261stars
MIT OR Apache-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
75/100Good
Development Activity80
Maintenance68
Community72
Maturity52
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture85
Code Quality84
Innovation70
Learning Curve80

yaml-rust2 is a pure Rust implementation of the YAML 1.2 specification for parsing and emitting YAML documents. It is a maintained continuation of the original yaml-rust crate, reworked with fixes that make it pass the official YAML test suite, and it exposes a straightforward loader/emitter API over an untyped Yaml document model.

Because it is written entirely in safe Rust with no C dependencies, yaml-rust2 avoids the memory-safety pitfalls of libyaml-based crates while remaining a lightweight, dependency-light choice. It loads YAML text into Yaml values you can traverse and mutate, and emits them back to well-formed YAML.

What You Get

  • A YAML 1.2 compliant parser validated against the official YAML test suite
  • YamlLoader for loading one or more documents into Yaml values
  • YamlEmitter for serializing Yaml values back to YAML text
  • A dynamic, untyped Yaml document model you can traverse and edit
  • A pure-Rust, memory-safe implementation with no C/libyaml dependency

Common Use Cases

  • Loading and inspecting application configuration written in YAML
  • Parsing YAML documents whose shape is not known at compile time
  • Generating YAML output from in-memory document structures
  • Replacing libyaml-based crates with a safe, pure-Rust parser

Under The Hood

Architecture - Parsing is layered: scanner.rs tokenizes YAML input, parser.rs turns tokens into an event stream, and yaml.rs builds the Yaml document tree consumed by callers. emitter.rs performs the reverse, serializing a Yaml value back to text, while char_traits.rs handles YAML character classification and lib.rs ties the public API together.

Tech Stack - Written in pure Rust (edition 2021, MSRV 1.65) with a minimal dependency set: arraydeque for the scanner’s buffer, hashlink for order-preserving mappings, and an optional encoding_rs for input encoding detection behind the default encoding feature. There is no C dependency.

Code Quality - Correctness is anchored by running the upstream yaml-test-suite as an integration test (via libtest-mimic) plus property testing with quickcheck, alongside example programs, a tools/ directory, and a maintained CHANGELOG.md. The README is candid that the crate now receives basic maintenance while new features move to the successor saphyr.

API Design - The loader/emitter pair keeps the surface small and approachable: parse text into Yaml, walk or mutate the tree, emit it back. It intentionally favors an untyped document model over Serde-style typed deserialization, which keeps it simple for dynamic YAML handling.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search