| Crates.io | fast-yaml-core |
| lib.rs | fast-yaml-core |
| version | 0.5.0 |
| created_at | 2025-12-13 22:07:52.948204+00 |
| updated_at | 2026-01-19 04:01:36.38177+00 |
| description | Core YAML 1.2.2 parser and emitter |
| homepage | |
| repository | https://github.com/bug-ops/fast-yaml |
| max_upload_size | |
| id | 1983484 |
| size | 155,655 |
Core YAML 1.2.2 parser and emitter for the fast-yaml ecosystem.
[!NOTE] This crate provides three distinct components: Parser (YAML → data), Emitter (data → YAML), and Streaming Formatter (events → YAML, no DOM).
Purpose: Deserialize YAML text into Rust data structures (DOM).
When to use:
Data flow: YAML text → Value (DOM)
Purpose: Serialize Rust data structures back to YAML text.
When to use:
Data flow: Value (DOM) → YAML text
Configuration: EmitterConfig allows customizing indent, line width, flow style, etc.
streaming)Purpose: Format YAML directly from parser events without building DOM.
When to use:
Data flow: Parser events → YAML text (zero-copy)
Advantages:
[!TIP] Use Streaming Formatter for CLI batch mode formatting. Use Parser + Emitter when you need to modify YAML data.
Add to your Cargo.toml:
[dependencies]
fast-yaml-core = "0.3"
Or with cargo-add:
cargo add fast-yaml-core
[!IMPORTANT] Requires Rust 1.88 or later.
use fast_yaml_core::{Parser, Value};
// Parse single document
let yaml = "name: test\nvalue: 123";
let doc = Parser::parse_str(yaml)?;
// Parse multiple documents
let yaml = "---\nfoo: 1\n---\nbar: 2";
let docs = Parser::parse_all_str(yaml)?;
# Ok::<(), Box<dyn std::error::Error>>(())
use fast_yaml_core::{Emitter, EmitterConfig, Value, Map, ScalarOwned};
// Basic emission
let value = Value::Value(ScalarOwned::String("hello".to_string()));
let yaml = Emitter::emit_str(&value)?;
// Custom configuration
let config = EmitterConfig::new()
.with_indent(4)
.with_width(120)
.with_explicit_start(true);
let emitter = Emitter::new(config);
let yaml = emitter.emit_str(&value)?;
# Ok::<(), Box<dyn std::error::Error>>(())
#[cfg(feature = "streaming")]
use fast_yaml_core::streaming::{format_yaml, FormatterBackend};
#[cfg(feature = "streaming")]
{
let yaml = "name: test\nvalue: 123";
// Format without building DOM (faster, less memory)
let formatted = format_yaml(yaml)?;
// Result: properly formatted YAML
assert!(formatted.contains("name: test"));
}
# Ok::<(), Box<dyn std::error::Error>>(())
[!TIP] Enable the
streamingfeature for formatter:fast-yaml-core = { version = "0.4", features = ["streaming"] }
This library implements the YAML 1.2.2 specification with the Core Schema:
| Type | Supported Values |
|---|---|
| Null | ~, null, empty |
| Boolean | true/false (lowercase only per YAML 1.2 Core Schema) |
| Integer | Decimal, 0o octal, 0x hex |
| Float | Standard, .inf, -.inf, .nan |
| String | Plain, single/double-quoted, literal (|), folded (>) |
[!NOTE] YAML 1.1 booleans (
yes/no/on/off) are treated as strings per YAML 1.2.2 spec.
| Feature | Description | Use Case |
|---|---|---|
streaming |
Event-based formatting without DOM | CLI tools, large file processing |
arena |
Arena-based memory allocation | High-performance parsing |
# Enable streaming formatter
fast-yaml-core = { version = "0.4", features = ["streaming"] }
# Enable arena allocation
fast-yaml-core = { version = "0.4", features = ["arena"] }
# Enable both
fast-yaml-core = { version = "0.4", features = ["streaming", "arena"] }
[!TIP] The
arenafeature provides 10-15% faster parsing for large documents by reducing allocator overhead.
This crate is part of the fast-yaml workspace:
fast-yaml-linter — YAML linting with rich diagnosticsfast-yaml-parallel — Multi-threaded YAML processingLicensed under either of Apache License, Version 2.0 or MIT License at your option.