expression

Nested TOML tables

Group related settings into nested tables. Match the nested structure with nested Rust structs. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): true 64 Common mistake: Putting nested properties at the document root and expecting a match.

Formal Syntax & Structure

rust syntaxrust
[section] followed by key = value

Working Example

Example Snippetrust
fn main() {    #[derive(serde::Deserialize)]    struct Cache { enabled: bool, limit: u32 }    #[derive(serde::Deserialize)]    struct Config { cache: Cache }    let c: Config = toml::from_str("[cache]\nenabled = true\nlimit = 64").unwrap();    println!("{} {}", c.cache.enabled, c.cache.limit);}
Rust Reference