8 stable releases

Uses new Rust 2024

new 2.0.1 Jul 5, 2025
2.0.0 Jun 17, 2025
1.0.7 Jun 4, 2025
1.0.6 May 20, 2025
1.0.1+deprecated May 8, 2024

#795 in Parser implementations

Download history 2/week @ 2025-04-05 116/week @ 2025-04-12 7/week @ 2025-04-19 3/week @ 2025-04-26 4/week @ 2025-05-03 15/week @ 2025-05-10 113/week @ 2025-05-17 127/week @ 2025-05-24 165/week @ 2025-05-31 19/week @ 2025-06-07 116/week @ 2025-06-14 24/week @ 2025-06-21 53/week @ 2025-06-28

224 downloads per month
Used in 2 crates (via sancus)

MIT/Apache

340KB
9K SLoC

panic-free GitHub Workflow Status crates.io crates.io crates.io docs.rs

This package is a fork of serde-yaml, designed to provide (mostly) panic-free operation. Specifically, it should not panic when encountering malformed YAML syntax. This makes the library suitable for safely parsing user-supplied YAML content.

This increased safety comes at the cost of some API restrictions: write access to indices and mappings has been removed. Read access remains possible, with Value::Null returned on invalid access. Also, from 2.0.1, duplicate keys are not longer permitted in YAML, returning proper error message instead.

We do not encourage using this crate beyond serialization with serde. If your use-case requires additional functionality, there are better-suited crates available, such as yaml-rust2 and the newer, more experimental saphyr, both capable of handling valid YAML that is not directly representable with Rust structures.

Since the API has changed to a more restrictive version, the major version number has been incremented.

If a panic does occur under some short and clear input, please report it as a bug.

Usage Example

Here's a concise example demonstrating how to parse YAML into a Rust structure using serde_yaml_bw with proper error handling:

use serde::{Serialize, Deserialize};

// Define the structure representing your YAML data.
#[derive(Debug, Deserialize)]
struct Config {
    name: String,
    enabled: bool,
    retries: i32,
}

fn main() {
    let yaml_input = r#"
        name: "My Application"
        enabled: true
        retries: 5
    "#;

    let config: Result<Config, _> = serde_yaml_bw::from_str(yaml_input);

    match config {
        Ok(parsed_config) => {
            println!("Parsed successfully: {:?}", parsed_config);
        }
        Err(e) => {
            eprintln!("Failed to parse YAML: {}", e);
        }
    }
}

Dependencies

~1.3–1.7MB
~34K SLoC