TOML to Rust Converter - Generate Rust Structs from TOML Online
Free online tool to convert TOML configuration files to Rust structs with serde support. Generate type-safe Rust code from Cargo.toml and app configs.
How to Convert TOML to Rust - Step by Step Guide
Input Your TOML Configuration
Start by providing your TOML configuration file for Rust struct generation. Whether you're working with Cargo.toml, application configs, or configuration files for your Rust application, you have several convenient options. Use AI assistants like Claude or Grok to further optimize the generated code:
Example: TOML Configuration Input
A typical TOML configuration file with nested tables:
[server] host = "localhost" port = 8080 ssl_enabled = true [database] name = "myapp_db" max_connections = 100 hosts = ["db1.com", "db2.com"]
Automatic Rust Code Generation
The converter instantly generates type-safe Rust structs with proper serde annotations:
#[derive(Serialize, Deserialize)] for TOML serializationExample: Generated Rust Structs
The same TOML converted to idiomatic Rust code:
use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub server: Server, pub database: Database, } #[derive(Debug, Serialize, Deserialize)] pub struct Server { pub host: String, pub port: i64, pub ssl_enabled: bool, }
Customize Generation Options
Tailor the generated Rust code to match your project's conventions and requirements:
Clone, PartialEq, Defaultpub, or leave them private to the moduleExport Your Rust Code
Get your generated Rust structs ready for your project! Multiple export options make integration seamless:
Frequently Asked Questions
What is TOML and why is it popular in Rust?
TOML (Tom's Obvious Minimal Language) is a simple, human-readable configuration file format. It's the standard format for Cargo.toml in Rust projects and is widely used for application configurations. Converting TOML to Rust structs ensures type-safe configuration loading with compile-time validation.
Can I use this to parse my Cargo.toml?
Yes. Paste the whole file or just the sections you care about, such as a custom [package.metadata] table. Each table becomes a struct, and you load the file with toml::from_str. Keep in mind Cargo allows several shapes for the same key (a dependency can be "1.0" or { version = "1.0" }), and the structs only cover the shape in your file.
What dependencies do I need to use the generated code?
Two crates: serde with the derive feature, and toml for reading the file (dates and mixed arrays also use types from the toml crate). Add to your Cargo.toml: serde = { version = "1.0", features = ["derive"] } and toml = "0.8".
How does the converter handle TOML tables and arrays?
Every table, like [server] or [a.b.c], gets its own struct. Arrays become Vec<T>, and every item is looked at, not just the first: if some [[products]] entries have a color and others don't, color becomes Option<String>, and a list holding 1 and 2.5 becomes Vec<f64>. Whole numbers are i64 (long IDs like 8901240544102066246 fit), 1.0 counts as a float, and dates become toml::value::Datetime. Empty arrays and arrays mixing types fall back to Vec<toml::Value>.
Can I convert the generated structs back to TOML?
Yes, as long as Serialize stays in the derive list: toml::to_string() writes the structs back out. Comments and the original formatting don't survive the trip, and fields that are None are left out.
Is the converter free to use?
Yes, and there's no sign-up. The conversion happens in your browser, so your config never leaves your machine. Uploaded files can be up to 10 MB; very large files may take a moment to convert.
Related Tools
JSON to Rust
Convert JSON data to Rust structs with serde Serialize/Deserialize traits
JSON Schema to Rust
Generate Rust types from JSON Schema with validation
YAML to Rust
Convert YAML configuration to Rust structs with serde
XML to Rust
Convert XML data to Rust structs with serde serialization support
CSV to Rust
Convert CSV data to Rust structs with field mapping
TypeScript to Rust
Convert TypeScript interfaces and types to Rust structs