Name Description Size
de.rs 45568
error.rs 7364
lib.rs [![github]](https://github.com/dtolnay/serde-yaml)&ensp;[![crates-io]](https://crates.io/crates/serde-yaml)&ensp;[![docs-rs]](https://docs.rs/serde-yaml) [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs <br> This crate is a Rust library for using the [Serde] serialization framework with data in [YAML] file format. This library does not reimplement a YAML parser; it uses [yaml-rust] which is a pure Rust YAML 1.2 implementation. [Serde]: https://github.com/serde-rs/serde [YAML]: https://yaml.org/ [yaml-rust]: https://github.com/chyh1990/yaml-rust # Examples ``` use std::collections::BTreeMap; fn main() -> Result<(), serde_yaml::Error> { // You have some type. let mut map = BTreeMap::new(); map.insert("x".to_string(), 1.0); map.insert("y".to_string(), 2.0); // Serialize it to a YAML string. let s = serde_yaml::to_string(&map)?; assert_eq!(s, "---\nx: 1.0\ny: 2.0\n"); // Deserialize it back to a Rust type. let deserialized_map: BTreeMap<String, f64> = serde_yaml::from_str(&s)?; assert_eq!(map, deserialized_map); Ok(()) } ``` ## Using Serde derive It can also be used with Serde's serialization code generator `serde_derive` to handle structs and enums defined in your own program. ``` # use serde_derive::{Serialize, Deserialize}; use serde::{Serialize, Deserialize}; #[derive(Debug, PartialEq, Serialize, Deserialize)] struct Point { x: f64, y: f64, } fn main() -> Result<(), serde_yaml::Error> { let point = Point { x: 1.0, y: 2.0 }; let s = serde_yaml::to_string(&point)?; assert_eq!(s, "---\nx: 1.0\ny: 2.0\n"); let deserialized_point: Point = serde_yaml::from_str(&s)?; assert_eq!(point, deserialized_point); Ok(()) } ``` 4109
mapping.rs A YAML mapping and its iterator types. 15028
number.rs 15336
path.rs 1211
ser.rs YAML Serialization This module provides YAML serialization with the type `Serializer`. 22541
value