yaml-rust2
A fully YAML 1.2 compliant YAML parser and emitter written in pure Rust.
Repository Health
Technical Analysis
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
YamlLoaderfor loading one or more documents intoYamlvaluesYamlEmitterfor serializingYamlvalues back to YAML text- A dynamic, untyped
Yamldocument 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.