### Build and Test Commands Source: https://github.com/yaml/yaml-serde/blob/main/CLAUDE.md Common development tasks executed via the Makes system within the project shell. ```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' ``` -------------------------------- ### Configure Dependencies Source: https://github.com/yaml/yaml-serde/blob/main/README.md Required dependencies for using Serde YAML with derive macros. ```toml [dependencies] serde = { version = "1.0", features = ["derive"] } yaml_serde = "0.10" ``` -------------------------------- ### Serialize and Deserialize Structs Source: https://github.com/yaml/yaml-serde/blob/main/README.md Shows how to use Serde derive macros to handle custom structs. ```rust use serde::{Serialize, Deserialize}; #[derive(Debug, PartialEq, Serialize, Deserialize)] struct Point { x: f64, y: f64, } fn main() -> Result<(), yaml_serde::Error> { let point = Point { x: 1.0, y: 2.0 }; let yaml = yaml_serde::to_string(&point)?; assert_eq!(yaml, "x: 1.0\ny: 2.0\n"); let deserialized_point: Point = yaml_serde::from_str(&yaml)?; assert_eq!(point, deserialized_point); Ok(()) } ``` -------------------------------- ### Add Dependency Source: https://github.com/yaml/yaml-serde/blob/main/README.md Include the required dependencies in your Cargo.toml file. ```toml [dependencies] serde = "1.0" yaml_serde = "0.10" ``` -------------------------------- ### Migrate by Updating Imports Source: https://github.com/yaml/yaml-serde/blob/main/README.md Add the dependency directly and update your source code imports from serde_yaml to yaml_serde. ```toml [dependencies] yaml_serde = "0.10" ``` -------------------------------- ### Serialize and Deserialize Collections Source: https://github.com/yaml/yaml-serde/blob/main/README.md Demonstrates converting a BTreeMap to a YAML string and back to a Rust type. ```rust use std::collections::BTreeMap; fn main() -> Result<(), yaml_serde::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 yaml = yaml_serde::to_string(&map)?; assert_eq!(yaml, "x: 1.0\ny: 2.0\n"); // Deserialize it back to a Rust type. let deserialized_map: BTreeMap = yaml_serde::from_str(&yaml)?; assert_eq!(map, deserialized_map); Ok(()) } ``` -------------------------------- ### Migrate with Package Renaming Source: https://github.com/yaml/yaml-serde/blob/main/README.md Use Cargo package renaming to migrate from serde_yaml without changing existing imports. ```toml [dependencies] serde_yaml = { package = "yaml_serde", version = "0.10" } ``` -------------------------------- ### Serialize and Deserialize Enums Source: https://github.com/yaml/yaml-serde/blob/main/README.md Illustrates handling enums using YAML's !tag syntax for variant identification. ```rust use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize, PartialEq, Debug)] enum Enum { Unit, Newtype(usize), Tuple(usize, usize, usize), Struct { x: f64, y: f64 }, } fn main() -> Result<(), yaml_serde::Error> { let yaml = " - !Newtype 1 - !Tuple [0, 0, 0] - !Struct {x: 1.0, y: 2.0} "; let values: Vec = yaml_serde::from_str(yaml).unwrap(); assert_eq!(values[0], Enum::Newtype(1)); assert_eq!(values[1], Enum::Tuple(0, 0, 0)); assert_eq!(values[2], Enum::Struct { x: 1.0, y: 2.0 }); // The last two in YAML's block style instead: let yaml = " - !Tuple - 0 - 0 - 0 - !Struct x: 1.0 y: 2.0 "; let values: Vec = yaml_serde::from_str(yaml).unwrap(); assert_eq!(values[0], Enum::Tuple(0, 0, 0)); assert_eq!(values[1], Enum::Struct { x: 1.0, y: 2.0 }); // Variants with no data can be written using !Tag or just the string name. let yaml = " - Unit # serialization produces this one - !Unit "; let values: Vec = yaml_serde::from_str(yaml).unwrap(); assert_eq!(values[0], Enum::Unit); assert_eq!(values[1], Enum::Unit); Ok(()) } ``` -------------------------------- ### Serialization Data Flow Source: https://github.com/yaml/yaml-serde/blob/main/CLAUDE.md The sequence of components involved in converting Rust types into YAML output. ```text user's Rust type → ser::Serializer (Serde serializer) → libyaml::emitter::Emitter → YAML bytes/string ``` -------------------------------- ### Deserialization Data Flow Source: https://github.com/yaml/yaml-serde/blob/main/CLAUDE.md The sequence of components involved in converting YAML input into Rust types. ```text input bytes/str/reader → loader::Loader (libyaml parser) → loader::Document (event list) → de::Deserializer (Serde visitor dispatch) → user's Rust type ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.