expression
Parse typed TOML configuration
Read a configuration document into a typed structure. A field type mismatch is a parse-to-type error; further application validation is still required. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): reports 4 Common mistake: Assuming every integer value is a sensible worker count.
Formal Syntax & Structure
rust syntaxrust
toml::from_str::<T>(text)Working Example
Example Snippetrust
fn main() { #[derive(serde::Deserialize)] struct Config { workers: u16, label: String } let c: Config = toml::from_str("workers = 4\nlabel = 'reports'").unwrap(); println!("{} {}", c.label, c.workers);}