Back to Rules
πŸ“‹

Yaml Serde CLAUDE.md

Strongly typed YAML library for Rust

yaml

by @yaml

Sourced from yaml/yaml-serde β€” Apache-2.0

View profile
CLAUDE.md
> Sourced from [yaml/yaml-serde](https://github.com/yaml/yaml-serde) β€” [Apache-2.0](https://github.com/yaml/yaml-serde/blob/a25959abfac3fa58e8b82b738faabdcec5e50568/CLAUDE.md).

# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

`yaml-serde` is the officially maintained fork of `serde_yaml`, bridging Rust's
Serde serialization framework with YAML.
It is published under the YAML organization and uses `libyaml-rs` for
low-level YAML parsing and emission.

## Common Commands

All commands use the Makes system (dependencies installed under `.cache/`).

```bash
make shell cmd='cargo build'
make shell cmd='cargo test'
make shell cmd='cargo test test_name'          # Run a single test
make shell cmd='cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic'
make shell cmd='cargo doc'
```

Clippy is run with pedantic lints enabled and `-Dwarnings` is implicit in CI.
Fix all Clippy warnings before committing.

## Architecture

The library has two main layers:

**High-level API (`lib.rs`):** Exports `from_str`, `from_slice`, `from_reader`,
`to_string`, `to_writer`, and Value-based conversions (`from_value`,
`to_value`).

**Core modules:**

- `de.rs` β€” Serde `Deserializer` impl; drives `loader.rs` to consume YAML
  events and feeds them into Serde visitors.
  Handles anchors/aliases, enum tags (`!TagName`), and multi-document YAML.
- `ser.rs` β€” Serde `Serializer` impl; uses `libyaml/emitter.rs` to write YAML.
  Determines scalar style (plain, quoted, literal) based on content.
- `loader.rs` β€” Wraps the libyaml parser into a `Document` (event list +
  alias map); called by `de.rs`.
- `value/` β€” The loosely-typed `Value` enum (`Null`, `Bool`, `Number`,
  `String`, `Sequence`, `Mapping`, `Tagged`) with its own Serialize/Deserialize
  impls in `value/ser.rs` and `value/de.rs`.
- `mapping.rs` β€” `Mapping` type backed by `IndexMap<Value, Value>` (preserves
  insertion order).
- `number.rs` β€” `Number` with internal `PosInt(u64)`, `NegInt(i64)`,
  `Float(f64)` variants.
- `libyaml/` β€” Thin safe wrappers around `libyaml-rs` FFI: `parser.rs`,
  `emitter.rs`, `tag.rs`, `error.rs`.
- `error.rs` β€” `Error` type with `Location` (line/column/index).
- `with.rs` β€” Helpers for `#[serde(with = "...")]` attributes.

**Data flow (deserialization):**

```
input bytes/str/reader
  β†’ loader::Loader (libyaml parser)
  β†’ loader::Document (event list)
  β†’ de::Deserializer (Serde visitor dispatch)
  β†’ user's Rust type
```

**Data flow (serialization):**

```
user's Rust type
  β†’ ser::Serializer (Serde serializer)
  β†’ libyaml::emitter::Emitter
  β†’ YAML bytes/string
```

## Key Dependencies

- `serde` β€” serialization framework
- `libyaml-rs` β€” C YAML parser/emitter, safe wrapper
- `indexmap` β€” ordered map for `Mapping`

## Tests

Tests live in `tests/`:

- `test_de.rs` β€” deserialization edge cases
- `test_ser.rs` / `test_serde.rs` β€” serialization and round-trip
- `test_error.rs` β€” error messages and locations
- `test_value.rs` β€” Value API

Fuzz targets are in `fuzz/`.
CI also runs Miri (with `-Zmiri-strict-provenance`) and minimal dependency
versions.

Add to your project

Paste into your project's CLAUDE.md or ~/.claude/CLAUDE.md for global rules.

More for Rust

MCP servers for Rust

Browse all MCP servers β†’

Browse by Tag

Get the Claude Code Starter Pack

Top CLAUDE.md rules for Next.js, TypeScript, Python, Go, and React β€” free.