Parsing TOML values
examples/toml/toml-parse/Cargo.toml
[package] name = "toml-parse" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] toml = "0.7.6"
examples/toml/toml-parse/src/main.rs
use toml::Table; fn main() { parse_toml_pairs(); } fn parse_toml_pairs() { let value = "name = 'bar'\nyear = 2023".parse::<Table>().unwrap(); assert_eq!(value["name"].as_str(), Some("bar")); println!("{}", value["name"].as_str().unwrap()); assert_eq!(value["year"].as_integer(), Some(2023)); println!("{}", value["year"].as_integer().unwrap()); }