Pure safe Rust · YAML 1.2.2 · MSRV 1.88

Safe, fast YAML 1.2.2 in pure Rust

ayaml parses, decodes, emits, and edits YAML 1.2.2 in pure safe Rust (#![forbid(unsafe_code)]), with default DoS limits and byte-accurate spans across every API.

2.12x-4.98x
Faster than established Rust peers
Geometric mean across shared pinned fixtures (up to 26) vs yaml-rust2, saphyr, noyalib, fast-yaml-core, and serde-saphyr (serde_json::Value) ; matches astral-yaml Value CPU (0.99x) at 3.85x lower peak heap (Tape: 1.42x faster, 5.89x lower peak) .
1.72x / 2.78x
Faster than C libyaml & libfyaml
Public pull-based ayaml::parse_events vs C libyaml (1.72x overall, 1.56x excl. 1 MiB plain scalar) and libfyaml (2.78x), with zero unsafe FFI.
2456 MiB/s
1 MiB plain-scalar throughput
1.56x vs libfyaml events (1575 MiB/s) and 8.5x vs C++ rapidyaml; up to 242 MiB/s deterministic emission.
5.1x fewer
Heap allocations vs yaml-serde
4.57x lower peak heap and 3.08x higher speed than libyaml-backed yaml-serde.
API tour

One parser across every workflow

All seven surfaces below run on the same scanner, schema resolver, and resource limits.

Typed Serde

src/config.rs
use ayaml::{from_str_borrowed, to_string};
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
struct Service<'a> {
    name: &'a str,
    ports: Vec<u16>,
    tls: bool,
}

let yaml = "name: api\nports: [8080, 8443]\ntls: true\n";
let svc: Service<'_> = from_str_borrowed(yaml)?;
let out = to_string(&svc)?;
Performance snapshot · Log scale vs ayaml (1.00x)

Comparative parse speed and memory on pinned fixtures

Geometric-mean ratios across shared fixtures (up to 26) in the ayaml-fixtures catalog relative to ayaml (Value DOM) = 1.00x. Measured on x86_64 Intel Skylake-class quad-core (8 threads) @ 2.60 GHz with pinned CPU affinity and 3-round median aggregation over SHA-256 verified inputs. New to labels like Tape DOM, ParserBuf, or C++ arena? See the parsing modes guide.

Parse time

Tier 2 parse time comparison vs ayaml value Geometric-mean parse time across shared pinned fixtures (up to 26), normalized to ayaml (Value DOM) = 1.00x on a log scale. Terracotta = ayaml (safe Rust), blue = unsafe C++ arena (rapidyaml), gray = slower peer. Tape DOM is cold flat-array zero-copy; Tape + ParserBuf measures warm buffer reuse (timing-only). Baseline: ayaml (1.00x) ← Faster than ayaml Slower than ayaml → 0.5x 1x 2x 4x 8x rapidyaml (C++ arena) 0.64x ayaml (Tape + ParserBuf) 0.69x ayaml (Tape DOM) 0.70x astral-yaml (serde Value) 0.99x ayaml (Value DOM) 1.00x ayaml (serde Value) 1.27x ayaml (compat serde) 1.33x fkYAML 1.87x yaml-rust2 2.12x noyalib 2.32x saphyr 2.44x fast-yaml-core 2.48x yaml-serde 3.08x serde-saphyr (JSON Value) 4.98x
Tier 2 parse time comparison vs ayaml value
Implementation Ratio vs baseline
rapidyaml (C++ arena) 0.64x
ayaml (Tape + ParserBuf) 0.69x
ayaml (Tape DOM) 0.70x
astral-yaml (serde Value) 0.99x
ayaml (Value DOM) 1.00x
ayaml (serde Value) 1.27x
ayaml (compat serde) 1.33x
fkYAML 1.87x
yaml-rust2 2.12x
noyalib 2.32x
saphyr 2.44x
fast-yaml-core 2.48x
yaml-serde 3.08x
serde-saphyr (JSON Value) 4.98x
Geometric-mean parse time across shared pinned fixtures (up to 26), normalized to ayaml (Value DOM) = 1.00x on a log scale. Terracotta = ayaml (safe Rust), blue = unsafe C++ arena (rapidyaml), gray = slower peer. Tape DOM is cold flat-array zero-copy; Tape + ParserBuf measures warm buffer reuse (timing-only).
View full benchmarks Parsing modes guide Includes Tier 1 C/C++ comparisons (including rapidyaml architectural trade-offs), typed Serde decode, emission, peak heap, 10x linear scaling, and reproduction commands.
Design guarantees

What the crate enforces

YAML 1.2.2

One scanner and grammar across every API

EventStream, Value, flat-array Tape, owned and borrowed Serde decoding, SpannedTree, and frontmatter share one YAML 1.2.2 core verified by the pinned YAML Test Suite, 25+ core-hour fuzz soak, Miri, 41 Kani proofs, and 0-missed mutation testing.

How correctness is verified →
#![forbid(unsafe_code)]

Pure safe Rust with 2 runtime dependencies

Published workspace crates forbid unsafe code and avoid C/libyaml FFI. Direct runtime dependencies are serde and indexmap.

Dependency policy →
Hardened defaults

Native DoS limits & redacted errors

Every parse, decode, merge expansion, reader, and emit call enforces explicit ceilings for input bytes, depth, collections, events, and byte-weighted alias expansion. Error::masked() strips document text.

Security model →
Byte-accurate spans

Spanned<T>, SpannedTree & source-preserving edits

Attach byte spans to typed Serde fields, convert offsets to UTF-8, scalar, or UTF-16 positions via LineIndex, or apply comment-preserving edits verified with ayaml-edit.

Spans & editing →
Zero-copy & streaming

Measured against Rust and C/C++ peers

Streams typed reads directly from events at every input size, borrows unescaped scalars in place, and offers a flat-array Tape DOM plus ParserBuf recycling for zero-allocation steady-state bulk parsing.

Read benchmarks →
Incremental migration

Opt-in merge keys & libyaml-compat boundary

Adopt YAML 1.2.2 immediately while opting into <<: merge keys per call or enabling the additive libyaml-compat feature for legacy inputs.

Compatibility profile →
Tested migration guides

Migrating from another Rust YAML crate

Every Rust snippet in the migration guides compiles and runs in CI via book_doctests, backed by integration tests covering behavioral differences.

Validated across 5 real-world Rust codebases 3,380 upstream tests across syntect, ast-grep, zizmor, prek, and rattler-build: 1.52x-4.76x faster parsing, 2.29x-41.1x fewer allocations, zero bugs.
Rustdoc API reference Full trait signatures, option builders, and module docs on docs.rs.