### Install yfm using npm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This command installs the yfm library and saves it as a dependency in your project's package.json file. It is a prerequisite for using the library in your Node.js application. ```bash npm i yfm --save ``` -------------------------------- ### Create Matter Parser Instance (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Instantiate a `Matter` parser with a specific engine (e.g., `YAML`). The parser uses `---` as the default delimiter for front matter and excerpts. This setup is ready for parsing. ```rust use gray_matter::Matter; use gray_matter::engine::YAML; fn main() { // Create a YAML parser with default settings let matter: Matter = Matter::new(); // Default configuration: // - delimiter: "---" // - close_delimiter: None (uses delimiter) // - excerpt_delimiter: None (uses delimiter) println!("Parser ready with default delimiter: ---"); } ``` -------------------------------- ### Implement Custom Front Matter Engine in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Demonstrates how to implement the `Engine` trait to create a custom parser for a key=value front matter format. It converts raw strings into `Pod` values and handles various data types. This example requires the `gray_matter` and `serde` crates. ```rust use gray_matter::{Matter, Pod, ParsedEntity, Result, Error}; use gray_matter::engine::Engine; use serde::Deserialize; // Custom engine that parses simple key=value format struct KeyValueEngine; impl Engine for KeyValueEngine { fn parse(content: &str) -> Result { let mut pod = Pod::new_hash(); for line in content.lines() { let line = line.trim(); if line.is_empty() || line.starts_with('#') { continue; // Skip empty lines and comments } if let Some((key, value)) = line.split_once('=') { let key = key.trim().to_string(); let value = value.trim(); // Try to parse as different types let pod_value = if value == "true" { Pod::Boolean(true) } else if value == "false" { Pod::Boolean(false) } else if let Ok(int) = value.parse::() { Pod::Integer(int) } else if let Ok(float) = value.parse::() { Pod::Float(float) } else { // Remove surrounding quotes if present let clean_value = value.trim_matches('"').trim_matches('''); Pod::String(clean_value.to_string()) }; pod.insert(key, pod_value)?; } } Ok(pod) } } #[derive(Deserialize, Debug)] struct CustomConfig { name: String, version: i64, enabled: bool, rate: f64, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- # Configuration file name = "My Application" version = 2 enabled = true rate = 0.95 --- # Application Documentation This is the main content. "###; let result: ParsedEntity = matter.parse(input)?; let config = result.data.unwrap(); println!("Name: {}", config.name); // "My Application" println!("Version: {}", config.version); // 2 println!("Enabled: {}", config.enabled); // true println!("Rate: {}", config.rate); // 0.95 // Also works with Pod let result2: ParsedEntity = matter.parse(input)?; let pod = result2.data.unwrap(); println!("Pod name: {}", pod["name"].as_string()?); Ok(()) } ``` -------------------------------- ### Parse Front Matter with ParsedEntity in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt This example demonstrates how to use the Matter engine to parse input text into a ParsedEntity struct. It shows how to access the deserialized metadata, content, excerpt, and raw matter fields using a custom Rust struct. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct Meta { title: String, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r#"--- title: Complete Example --- This is the excerpt section. --- This is the main content that follows the excerpt delimiter. More content here. "#; let result: ParsedEntity = matter.parse(input)?; println!("Data: {:?}", result.data); println!("\nContent:\n{}", result.content); println!("\nExcerpt: {:?}", result.excerpt); println!("\nOriginal length: {}", result.orig.len()); println!("\nMatter:\n{}", result.matter); Ok(()) } ``` -------------------------------- ### Install gray-matter with Features Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Add gray_matter to your Cargo.toml, specifying feature flags for desired format support (e.g., yaml, json, toml). You can enable all formats or specific ones. ```toml [dependencies] # With YAML support (default) gray_matter = "0.3" # With all formats gray_matter = { version = "0.3", features = ["yaml", "json", "toml"] } # JSON only gray_matter = { version = "0.3", default-features = false, features = ["json"] } ``` -------------------------------- ### Gray Matter Error Handling in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Illustrates how gray-matter handles parsing and type conversion errors using a custom `Error` type and `Result` alias. Examples include deserialization failures, type mismatches when accessing `Pod` values, invalid YAML syntax, and graceful handling of missing front matter. This snippet requires the `gray_matter` and `serde` crates. ```rust use gray_matter::{Matter, ParsedEntity, Result, Error, Pod}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct StrictConfig { required_field: String, count: i64, } fn main() { let matter: Matter = Matter::new(); // Example 1: Missing required field let bad_input = r###"--- count: 42 --- Content"###; let result: Result> = matter.parse(bad_input); match result { Ok(parsed) => println!("Parsed: {:?}", parsed.data), Err(Error::DeserializeError(msg)) => { println!("Deserialization failed: {}", msg); } Err(e) => println!("Other error: {}", e), } // Example 2: Type mismatch when accessing Pod let input = r###"--- value: not_a_number --- Content"###; let result: ParsedEntity = matter.parse(input).unwrap(); let data = result.data.unwrap(); match data["value"].as_i64() { Ok(num) => println!("Number: {}", num), Err(Error::TypeError(expected)) => { println!("Type error: expected {}", expected); // "expected Integer" } Err(e) => println!("Other error: {}", e), } // Example 3: Invalid YAML syntax let invalid_yaml = r###"--- key: [unclosed bracket --- Content"###; match matter.parse::<()>(invalid_yaml) { Ok(_) => println!("Parsed successfully"), Err(Error::DeserializeError(msg)) => { println!("YAML parse error: {}", msg); } Err(e) => println!("Other error: {}", e), } // Example 4: Graceful handling of missing front matter let no_front_matter = "Just plain content without front matter"; let result: ParsedEntity = matter.parse(no_front_matter).unwrap(); match result.data { Some(data) => println!("Has data: {:?}", data), None => println!("No front matter found - content: {}", result.content), } } ``` -------------------------------- ### Define YAML Front Matter Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md Demonstrates the syntax for adding YAML front matter to documents. This allows users to inject custom metadata into project templates. ```yaml --- username: jonschlinkert --- ``` -------------------------------- ### Basic Usage of yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript snippet demonstrates the basic usage of the yfm library by parsing a file named 'yfm.html'. It requires the 'yfm' module and calls the main function with the file path. ```javascript var yfm = require('yfm'); yfm('yfm.html'); ``` -------------------------------- ### Configure custom close delimiter Source: https://github.com/yuchanns/gray-matter-rs/blob/main/README.md Demonstrates how to set distinct opening and closing delimiters for front matter blocks. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; fn main() -> Result<()> { let mut matter: Matter = Matter::new(); matter.delimiter = "".to_owned()); matter.excerpt_delimiter = Some("".to_owned()); #[derive(Deserialize, Debug)] struct FrontMatter { abc: String, } let result: ParsedEntity = matter.parse( "\nfoo\nbar\nbaz\n\ncontent", )?; Ok(()) } ``` -------------------------------- ### Configure custom delimiters Source: https://github.com/yuchanns/gray-matter-rs/blob/main/README.md Shows how to modify the Matter struct to support non-standard front matter delimiters and excerpt separators. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; fn main() -> Result<()> { let mut matter: Matter = Matter::new(); matter.delimiter = "~~~".to_owned(); matter.excerpt_delimiter = Some("".to_owned()); #[derive(Deserialize, Debug)] struct FrontMatter { abc: String, } let result: ParsedEntity = matter.parse( "~~\nabc: xyz\n~~\nfoo\nbar\nbaz\n\ncontent", )?; Ok(()) } ``` -------------------------------- ### Parse TOML Package Configuration in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Demonstrates parsing a TOML file into a PackageConfig struct using the gray-matter library. It shows how to access package name, version, authors, and dependency versions. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::TOML; #[derive(serde::Deserialize)] struct PackageConfig { name: String, version: String, authors: Vec, dependencies: Dependencies, } #[derive(serde::Deserialize)] struct Dependencies { serde: String, tokio: Option, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r#"--- name = "my-awesome-crate" version = "0.1.0" authors = ["Alice ", "Bob "] [dependencies] serde = "1.0" tokio = { version = "1.28", features = ["full"] } --- Content "#; let result: ParsedEntity = matter.parse(input)?; let config = result.data.unwrap(); println!("Package: {}", config.name); // "my-awesome-crate" println!("Version: {}", config.version); // "0.1.0" println!("Authors: {:?}", config.authors); // ["Alice ", "Bob "] println!("Serde version: {}", config.dependencies.serde); // "1.0" println!("Tokio version: {:?}", config.dependencies.tokio); // Some("1.28") Ok(()) } ``` -------------------------------- ### Generic YAML Configuration Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md A basic YAML block representing configuration or data definitions used within the project. ```yaml foo: bar version: 2 ``` -------------------------------- ### Parse front matter with YAML engine Source: https://github.com/yuchanns/gray-matter-rs/blob/main/README.md Demonstrates basic usage of the Matter struct to parse YAML front matter into a custom Rust struct or a generic Pod type. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; const INPUT: &str = r#"--- title: gray-matter-rs tags: - gray-matter - rust --- Some excerpt --- Other stuff "#; fn main() -> Result<()> { let matter = Matter::::new(); let result: ParsedEntity = matter.parse(INPUT)?; assert_eq!(result.content, "Some excerpt\n---\nOther stuff"); assert_eq!(result.excerpt, Some("Some excerpt".to_owned())); #[derive(Deserialize, Debug)] struct FrontMatter { title: String, tags: Vec } let result_with_struct = matter.parse::(INPUT)?; println!("{:?}", result_with_struct.data); Ok(()) } ``` -------------------------------- ### Configure Custom Delimiters for Front Matter (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Illustrates how to customize front matter delimiters in Rust using the gray-matter crate. It shows setting custom delimiters like `~~~`, HTML comment style (``), and TOML-style (`+++`). Also demonstrates configuring a custom excerpt delimiter. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct Config { title: String, version: String, } fn main() -> Result<()> { // Example 1: Using ~~~ as delimiter let mut matter: Matter = Matter::new(); matter.delimiter = "~~~".to_owned(); let input1 = r###"~~~ title: Custom Delimiter Example version: 1.0.0 ~~~ Content here ###; let result1: ParsedEntity = matter.parse(input1)?; println!("Title: {}", result1.data.unwrap().title); // "Custom Delimiter Example" // Example 2: Different open and close delimiters (HTML comment style) let mut matter2: Matter = Matter::new(); matter2.delimiter = "".to_owned()); let input2 = r###"

My Document

###; let result2: ParsedEntity = matter2.parse(input2)?; println!("Title: {}", result2.data.unwrap().title); // "HTML Comment Style" // Example 3: Custom excerpt delimiter let mut matter3: Matter = Matter::new(); matter3.excerpt_delimiter = Some("".to_owned()); let input3 = r###"--- title: With Custom Excerpt version: 3.0.0 --- This is the excerpt summary. This is the full content that comes after the excerpt. ###; let result3: ParsedEntity = matter3.parse(input3)?; println!("Excerpt: {:?}", result3.excerpt); // Some("This is the excerpt summary.") println!("Content: {}", result3.content); // "This is the excerpt summary.\n\nThis is the full content..." // Example 4: TOML-style +++ delimiters let mut matter4: Matter = Matter::new(); matter4.delimiter = "+++".to_owned(); let input4 = "+++\ntitle: TOML Style\nversion: 4.0.0\n+++\nContent"; let result4: ParsedEntity = matter4.parse(input4)?; println!("Title: {}", result4.data.unwrap().title); // "TOML Style" Ok(()) } ``` -------------------------------- ### Extract Front Matter and Content with yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript code snippet shows how to extract the parsed YAML front-matter (context), content, and original string from an HTML file using the yfm library. The output is a JSON object containing these properties. ```javascript console.log(yfm('foo.html')); ``` -------------------------------- ### Handlebars Template Comments Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md Syntax for including comments within Handlebars templates that will be stripped during the rendering process. ```handlebars [[!-- foo --]] [[! foo ]] [[!foo]] ``` -------------------------------- ### Add dependency to Cargo.toml Source: https://github.com/yuchanns/gray-matter-rs/blob/main/README.md Instructions for adding the gray_matter crate to a Rust project's dependencies. ```toml [dependencies] # other dependencies... gray_matter = "0.3" ``` -------------------------------- ### Parse TOML Front Matter with TOML Engine (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Shows how to parse TOML formatted front matter using the `TOML` engine from the gray-matter crate. This requires enabling the `toml` feature flag. It demonstrates deserializing TOML data into Rust structs, including nested structures and vectors. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::TOML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct PackageConfig { name: String, version: String, authors: Vec, dependencies: Dependencies, } #[derive(Deserialize, Debug)] struct Dependencies { serde: String, tokio: Option, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- name = "my-awesome-crate" version = "0.1.0" authors = ["Alice ", "Bob "] [dependencies] serde = "1.0" tokio = "1.28" --- "###; let result: ParsedEntity = matter.parse(input)?; let config = result.data.unwrap(); println!("Package Name: {}", config.name); println!("Package Version: {}", config.version); println!("Authors: {:?}", config.authors); println!("Serde Version: {}", config.dependencies.serde); println!("Tokio Version: {:?}", config.dependencies.tokio); Ok(()) } ``` -------------------------------- ### Parse Front Matter into BlogPost Struct (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Demonstrates parsing front matter directly into a strongly-typed BlogPost struct using the gray-matter crate. It shows how to access parsed data fields like title, author, tags, and content. Assumes the `BlogPost` struct is defined elsewhere and derives `Deserialize`. ```rust use gray_matter::{Matter, ParsedEntity}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct BlogPost { title: String, author: String, tags: Vec, published: bool, draft: bool, views: Option, } fn main() -> Result<(), Box> { let input = r#"--- title: Understanding Rust Lifetimes author: Alice Smith tags: - rust - lifetimes - advanced published: true views: 2500 --- Lifetimes are Rust's way of ensuring memory safety..."#; // Parse directly into the BlogPost struct let result: ParsedEntity = matter.parse(input)?; // Access strongly-typed data let post = result.data.unwrap(); println!("Title: {}", post.title); // "Understanding Rust Lifetimes" println!("Author: {}", post.author); // "Alice Smith" println!("Tags: {:?}", post.tags); // ["rust", "lifetimes", "advanced"] println!("Published: {}", post.published); // true println!("Draft: {}", post.draft); // false (default value) println!("Views: {:?}", post.views); // Some(2500) // Content is still accessible println!("\nContent:\n{}", result.content); Ok(()) } ``` -------------------------------- ### Parse JSON Front Matter with JSON Engine (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Demonstrates parsing JSON formatted front matter using the `JSON` engine from the gray-matter crate. This requires enabling the `json` feature flag. It shows deserializing JSON data into a struct with nested objects. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::JSON; use serde::Deserialize; #[derive(Deserialize, Debug)] struct ApiConfig { endpoint: String, version: i32, auth: AuthConfig, } #[derive(Deserialize, Debug)] struct AuthConfig { enabled: bool, method: String, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- { "endpoint": "/api/v2/users", "version": 2, "auth": { "enabled": true, "method": "bearer" } } --- # API Documentation This endpoint returns a list of users. ###; let result: ParsedEntity = matter.parse(input)?; let config = result.data.unwrap(); println!("Endpoint: {}", config.endpoint); // "/api/v2/users" println!("Version: {}", config.version); // 2 println!("Auth enabled: {}", config.auth.enabled); // true println!("Auth method: {}", config.auth.method); // "bearer" println!("\nDocumentation:\n{}", result.content); Ok(()) } ``` -------------------------------- ### Parse Front Matter to Pod (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Parse input text using a `Matter` instance to extract front matter into the flexible `Pod` data type. The result includes parsed data, content, optional excerpt, original input, and raw front matter. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- title: My Blog Post author: Jane Doe tags: - rust - programming published: true views: 1500 --- This is the excerpt that appears before the second delimiter. --- # Introduction This is the main content of the blog post. "###; let result: ParsedEntity = matter.parse(input)?; // Access parsed front matter via Pod indexing let data = result.data.as_ref().unwrap(); println!("Title: {}", data["title"].as_string()?); // "My Blog Post" println!("Author: {}", data["author"].as_string()?); // "Jane Doe" println!("Published: {}", data["published"].as_bool()?); // true println!("Views: {}", data["views"].as_i64()?); // 1500 // Access array elements println!("First tag: {}", data["tags"][0].as_string()?); // "rust" println!("Second tag: {}", data["tags"][1].as_string()?); // "programming" // Access content (includes excerpt) println!("\nContent:\n{}", result.content); // "This is the excerpt that appears before the second delimiter.\n---\n# Introduction\n\nThis is the main content of the blog post." // Access excerpt (text between front matter and second delimiter) println!("\nExcerpt: {:?}", result.excerpt); // Some("This is the excerpt that appears before the second delimiter.") // Access raw front matter string println!("\nRaw matter:\n{}", result.matter); // "title: My Blog Post\nauthor: Jane Doe\n..." // Original input is preserved assert_eq!(result.orig, input); Ok(()) } ``` -------------------------------- ### Parse Front Matter to Struct (Rust) Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Parse front matter directly into a custom struct implementing `serde::Deserialize`. This offers type safety and a more ergonomic way to access front matter data compared to `Pod` indexing. ```rust use gray_matter::{Matter, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct BlogPost { title: String, author: String, tags: Vec, published: bool, #[serde(default)] draft: bool, views: Option, } fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- title: Understanding Rust Lifetimes author: Alice Smith tags: - rust - lifetimes - advanced published: true views: 2500 --- "###; let result: ParsedEntity = matter.parse_with_struct(input)?; // Access parsed front matter via the deserialized struct println!("Title: {}", result.data.title); println!("Author: {}", result.data.author); println!("Published: {}", result.data.published); println!("Views: {:?}", result.data.views); println!("Draft: {}", result.data.draft); // Access content println!("\nContent:\n{}", result.content); Ok(()) } ``` -------------------------------- ### Custom Delimiters for yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript object shows how to configure custom open and close delimiters for YAML front-matter parsing in yfm. Delimiters can be strings or arrays of strings to match multiple patterns. ```javascript { close: ['---', '~~~'], open: ['...', '---'] } ``` -------------------------------- ### Access Parsed YAML Context with yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript code snippet demonstrates how to specifically access the parsed YAML front-matter (context) from the result of the yfm function. It logs only the context object, which contains the key-value pairs from the YAML. ```javascript console.log(yfm('foo.html').context); ``` -------------------------------- ### Check for YAML Front Matter using yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript function, 'hasYFM', checks if a given source string contains YAML front matter by parsing it with yfm and examining the length of the 'context' object. It returns true if front matter is present, false otherwise. ```javascript var hasYFM = function (src, options) { var obj = yfm(src, options).context; return _.keys(obj).length > 0; }; ``` -------------------------------- ### Deserialize Pod to Struct in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Demonstrates how to deserialize a `Pod` value into any Rust struct that implements the `serde::Deserialize` trait. This is useful for conditionally parsing data into typed structs after an initial parse into `Pod`. ```rust use gray_matter::{Matter, Pod, ParsedEntity, Result}; use gray_matter::engine::YAML; use serde::Deserialize; #[derive(Deserialize, Debug)] struct SimpleConfig { title: String, count: i64, } #[derive(Deserialize, Debug)] struct ComplexConfig { title: String, metadata: Metadata, tags: Vec, } #[derive(Deserialize, Debug)] struct Metadata { author: String, date: String, } fn main() -> Result<()> { let matter: Matter = Matter::new(); // Parse to Pod first let input = r###"--- title: Dynamic Parsing metadata: author: John date: 2024-01-15 tags: - rust - parsing count: 42 --- Content ###; let result: ParsedEntity = matter.parse(input)?; let pod = result.data.unwrap(); // Deserialize Pod to different structs based on content if pod["metadata"]["author"].as_string().is_ok() { let complex: ComplexConfig = pod.deserialize()?; println!("Complex config - Author: {}", complex.metadata.author); println!("Complex config - Tags: {:?}", complex.tags); } // Build Pod manually and deserialize let mut manual_pod = Pod::new_hash(); manual_pod["title"] = Pod::String("Manual Entry".to_string()); manual_pod["count"] = Pod::Integer(100); let simple: SimpleConfig = manual_pod.deserialize()?; println!("Simple config - Title: {}", simple.title); println!("Simple config - Count: {}", simple.count); Ok(()) } ``` -------------------------------- ### Disable File Reading in yfm Source: https://github.com/yuchanns/gray-matter-rs/blob/main/tests/fixtures/complex.md This JavaScript snippet demonstrates how to use the 'read: false' option with yfm to parse a raw string instead of reading from a file. This is useful when the front-matter and content are already available as strings. ```javascript yfm('---\nTitle: YFM\n---\nContent.', {read: false}) ``` -------------------------------- ### Work with Pod Data Type in Rust Source: https://context7.com/yuchanns/gray-matter-rs/llms.txt Illustrates the usage of the Pod (Polyglot Object Data) type in Rust for representing and manipulating various data structures like strings, integers, floats, booleans, arrays, and nested objects. It covers type-specific accessors, array indexing, nested object access, and programmatic building of Pod values. ```rust use gray_matter::{Matter, Pod, ParsedEntity, Result}; use gray_matter::engine::YAML; fn main() -> Result<()> { let matter: Matter = Matter::new(); let input = r###"--- string_val: hello world integer_val: 42 float_val: 3.14159 bool_val: true array_val: - item1 - item2 - 100 nested: key1: value1 key2: value2 --- Content ###; let result: ParsedEntity = matter.parse(input)?; let data = result.data.unwrap(); // Type-specific accessors println!("String: {}", data["string_val"].as_string()?); // "hello world" println!("Integer: {}", data["integer_val"].as_i64()?); // 42 println!("Float: {}", data["float_val"].as_f64()?); // 3.14159 println!("Boolean: {}", data["bool_val"].as_bool()?); // true // Array access by index println!("Array[0]: {}", data["array_val"][0].as_string()?); // "item1" println!("Array[2]: {}", data["array_val"][2].as_i64()?); // 100 // Nested object access println!("Nested key1: {}", data["nested"]["key1"].as_string()?); // "value1" // Get array as Vec let array = data["array_val"].as_vec()?; println!("Array length: {}", array.len()); // 3 // Get hash as HashMap let nested = data["nested"].as_hashmap()?; println!("Nested keys: {:?}", nested.keys().collect::>()); // Check length and emptiness println!("Array len: {}", data["array_val"].len()); // 3 println!("Nested len: {}", data["nested"].len()); // 2 println!("Is string empty: {}", data["string_val"].is_empty()); // true (len only works on array/hash) // Building Pod values programmatically let mut custom_pod = Pod::new_hash(); custom_pod["name"] = Pod::String("Test".to_string()); custom_pod["count"] = Pod::Integer(10); custom_pod["active"] = Pod::Boolean(true); let mut items = Pod::new_array(); items.push(Pod::String("first".to_string()))?; items.push(Pod::Integer(2))?; custom_pod["items"] = items; println!("Custom pod name: {}", custom_pod["name"].as_string()?); println!("Custom pod items[0]: {}", custom_pod["items"][0].as_string()?); Ok(()) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.