Loading Rust to CSV Converter...
How to Convert Rust Structs to CSV
Test fixtures, seed data and debug output in Rust often end up as a long vec! of structs. Paste it here and you get a table you can open in a spreadsheet, without writing a csv::Writer loop first.
Paste your Rust values
Paste a struct value such as User { id: 1, name: "Ann".to_string() }, a vec![...] or [...] of them, or a whole let statement. You can also upload a .rs file or click Sample. A file with struct definitions and a fn main works too: the value of the first let statement is used.
vec![
Order {
id: 8901240544102066246,
customer: Customer { name: "Ann Lee".to_string(), city: "Oslo".into() },
total: 14.50,
zip: "00501".to_string(),
note: Some("ring twice, gate 4".to_string()),
},
Order {
id: 2,
customer: Customer { name: "Bo".to_string(), city: "Rome".into() },
total: 9.99,
zip: "10115".to_string(),
note: None,
},
]Check the CSV
The CSV appears on the right a moment after you stop typing. Field names become the header row and each struct in the list becomes one row. If something in the input is not plain data, such as a variable or a macro call, the error names the line and column.
The example above comes out like this. The note with a comma is quoted, the empty note is an empty field, and the ID and the zero in 14.50 are untouched:
id,customer.name,customer.city,total,zip,note 8901240544102066246,Ann Lee,Oslo,14.50,00501,"ring twice, gate 4" 2,Bo,Rome,9.99,10115,
Copy or download it
Copy puts the CSV on your clipboard. Download saves data.csv as UTF-8 with a byte-order mark, so Excel shows accented names and emoji correctly.
What is Rust to CSV Conversion?
CSV is a table in plain text: one header row and one line per record. Rust data maps onto it naturally when you have a list of structs of the same type, because each struct is a record and each field is a column.
In a program you would write the rows with the csv crate and Serde. This page is for the moments when the data is already sitting in your source or your logs. Need a different format? Try Rust to JSON or Rust to XML, or go the other way with CSV to Rust, which writes a struct for a CSV file.
Frequently Asked Questions
What Rust input does the converter accept?
Data written as Rust values: a struct literal like User { id: 1, name: "Ann".to_string() }, a vec![...] or array of them, tuples, or a let users = vec![...]; statement. Strings can use any Rust form (escapes like \n and \u{1F600}, raw strings r#"..."#, byte strings and chars), numbers can carry suffixes and underscores (1_000u32), and .to_string(), .into(), String::from(...), Some(...) and None are understood. A struct definition on its own only lists types, so there is nothing to put in rows; paste the values instead.
How are nested structs, Vec fields and enums written?
A nested struct becomes dotted columns, so customer: Customer { city: "Oslo" } ends up in a customer.city column. A Vec of plain values stays in one cell with the items separated by "; ". A Vec of structs is spread over numbered columns such as items.0.sku and items.1.sku. None becomes an empty cell, true and false stay as words, and a unit enum value like Status::Active is written as Active, the same as the csv crate does.
Will my numbers change?
No. Numbers are copied as text, never turned into JavaScript numbers, so 8901240544102066246 and -9223372036854775808 keep every digit and 14.50 keeps its trailing zero. Underscores and type suffixes are dropped (1_000u32 becomes 1000), and hex, octal and binary literals are written as decimal, because that is the value Rust stores. Spreadsheets are a different story: Excel shows only 15 significant digits, so open long IDs as text there.
Can I open the CSV in Excel or Google Sheets?
Yes. Values that contain a comma, a double quote, a line break or leading and trailing spaces are wrapped in double quotes, with inner quotes doubled, as RFC 4180 describes. The downloaded file starts with a UTF-8 byte-order mark so Excel reads non-English text correctly; Copy gives you the plain CSV without it.
How does this compare to the csv crate?
The rows match what csv::Writer::serialize writes for the same structs in the common cases: the header comes from the field names and None is an empty field. Two things differ on purpose. The csv crate refuses nested structs and Vec fields, while this page flattens them, and it prints an f64 like 14.50 as 14.5, while this page keeps what you typed. Use it to preview data or export a quick list, and use the crate in your program.
Is my data uploaded anywhere?
No. The conversion runs in your browser, the text is not sent to our server, and nothing is kept: a reload starts with an empty editor. Uploaded files are read in the browser too, up to 10 MB.
Related Tools
Rust to JSON
Convert Rust structs and data structures to JSON format
Rust to YAML
Convert Rust structs to YAML configuration format
Rust to TOML
Convert Rust structs to TOML configuration format
Rust to XML
Convert Rust structs to XML format
Rust to SQL
Generate SQL CREATE TABLE and INSERT statements from Rust structs
Rust to Protobuf
Generate Protocol Buffers schema from Rust structs for gRPC