Use the toml crate to parse TOML files into Rust structs by defining a struct with #[derive(Deserialize)] and calling toml::from_str.
use serde::Deserialize;
#[derive(Deserialize)]
struct Config {
name: String,
version: u32,
}
fn main() {
let toml_str = r#"
name = "my-project"
version = 1
"#;
let config: Config = toml::from_str(toml_str).unwrap();
println!("{} v{}", config.name, config.version);
}