---
title: "oneyaml Rust cookbook"
url: https://recursiveai.org/oneyaml/rust/cookbook/
description: "Short recipes for common YAML tasks in Rust with oneyaml, each a complete program that was compiled and run against oneyaml 1.2.0."
version: "1.2.0"
---

# oneyaml Rust cookbook

Short recipes for common YAML tasks in Rust with oneyaml, each a complete program that was compiled and run against oneyaml 1.2.0.

## Recipes

- [Parse YAML into Rust structs](https://recursiveai.org/oneyaml/rust/cookbook/parse-yaml-into-structs/index.md): Read a YAML file into Rust structs and enums with serde and oneyaml, with renamed fields, defaults, optional sections and an enum.
- [Read YAML without a schema](https://recursiveai.org/oneyaml/rust/cookbook/read-yaml-without-a-schema/index.md): Read YAML of unknown shape into oneyaml::Value in Rust, index it by key and position, and walk a mapping in file order.
- [Edit YAML and keep its comments](https://recursiveai.org/oneyaml/rust/cookbook/edit-yaml-keep-comments/index.md): Change a value, remove a list item and add a key with a comment in a YAML file from Rust, with every other byte and comment kept.
- [Merge or patch YAML](https://recursiveai.org/oneyaml/rust/cookbook/patch-yaml/index.md): Apply a merge patch (RFC 7396) as an environment overlay and a guarded JSON Patch (RFC 6902) to a YAML file in Rust, keeping its comments.
- [Convert YAML to JSON and back](https://recursiveai.org/oneyaml/rust/cookbook/yaml-to-json/index.md): Convert YAML to JSON with oneyaml and serde_json in Rust, convert JSON back to YAML, and get an error instead of a silent change for values JSON can’t hold.
- [Read Kubernetes manifests and multi-document YAML](https://recursiveai.org/oneyaml/rust/cookbook/kubernetes-multi-document/index.md): Read every document of a multi-document YAML file such as a Kubernetes manifest into Rust structs, then edit one document and keep the rest byte for byte.
- [Report errors with line and column](https://recursiveai.org/oneyaml/rust/cookbook/errors-with-line-and-column/index.md): Get the Y#### code, line, column and path of a YAML error in Rust, print a rustc-style snippet, and collect every error in a file at once.
- [Anchors, aliases and merge keys](https://recursiveai.org/oneyaml/rust/cookbook/anchors-aliases-merge-keys/index.md): Read YAML anchors and aliases in Rust, turn on << merge keys for docker-compose-style files, and follow an alias to its anchor in a Document.
- [Read untrusted YAML safely](https://recursiveai.org/oneyaml/rust/cookbook/untrusted-input/index.md): Read YAML from the network in Rust with Limits::untrusted(), and refuse billion-laughs alias bombs and deep nesting with a clear error instead of running out of memory.
- [Read YAML 1.1 files: yes, no and 0755](https://recursiveai.org/oneyaml/rust/cookbook/yaml-1-1-booleans/index.md): Why oneyaml reads yes, no and 0755 the YAML 1.2 way in Rust, and how to read a YAML 1.1 file the old way with one setting or the Compat::yaml_1_1() preset.
