serde_yaml_ng
Strongly typed, Serde-compatible YAML serialization and deserialization for Rust.
Repository Health
Technical Analysis
serde_yaml_ng is a Rust library for reading and writing YAML using the Serde serialization framework. It is an independent, actively maintained continuation of David Tolnay’s original serde-yaml crate, forked from its final commit with the explicit goal of preserving that library’s behavior and quality.
With serde_yaml_ng you serialize any Serde-derivable type to a YAML string and deserialize YAML back into strongly typed Rust structs, enums, and collections. It follows the YAML 1.1 specification and integrates seamlessly with #[derive(Serialize, Deserialize)], making it a drop-in choice for configuration files, data interchange, and test fixtures.
What You Get
- A Serde
SerializerandDeserializerimplementation for the YAML 1.1 format - Simple top-level helpers:
to_string,to_writer,from_str,from_slice, andfrom_reader - A dynamic
Valuetype and orderedMappingfor working with arbitrary YAML documents - Full support for Serde derive macros on structs and enums, including YAML
!tagenum syntax - Behavioral compatibility with the original serde-yaml crate it forks
Common Use Cases
- Loading and validating application configuration files at startup
- Serializing Rust data structures to YAML for storage or interchange
- Parsing YAML fixtures and documents into typed structs in tests and tooling
- Migrating projects off the unmaintained serde-yaml crate with minimal changes
Under The Hood
Architecture - The crate is organized around Serde’s data model: ser.rs implements the Serializer that walks Rust values into YAML events, de.rs (the largest module at ~1,850 lines) implements the Deserializer, and loader.rs drives the underlying libyaml parser to produce a document tree consumed by value/ and mapping.rs. Top-level functions in lib.rs (to_string, from_str, etc.) are thin wrappers over these components, and with.rs provides adapters for customizing field-level (de)serialization.
Tech Stack - Written in Rust (edition 2021, MSRV 1.64), it depends on serde for the data model, unsafe-libyaml for YAML parsing/emitting, indexmap for order-preserving mappings, and itoa/ryu for fast integer and float formatting. It has no build scripts beyond Cargo and ships a fuzz target for the parser.
Code Quality - The repository includes a dedicated tests/ suite (test_de.rs, test_ser.rs, test_error.rs, test_value.rs) plus a fuzz/ harness, inherited and maintained from the mature upstream crate. Module boundaries are clean and errors are modeled explicitly in error.rs with location paths in path.rs. The maintainer is candid that active development is intermittent.
API Design - The public surface mirrors serde_json’s ergonomics, so developers already familiar with Serde need almost no ramp-up: derive your types, call to_string/from_str, and handle a single Error type. Enum handling via YAML !tag syntax and a dynamic Value type round out an API that is both minimal and expressive.