Serialization Without Crates
CSV Row
Format a Simple Record
Serialization turns typed values into text. A small CSV row can be built directly from fixed fields.
Program
Play the program to choose a quantity and watch the record become a comma-separated row.
csv_row_builder.rs
fn main() {
let quantity = ;
let item = ("book", quantity, 12);
let row = csv_row(item.0, item.1, item.2);
println!("{row}");
}
fn csv_row(name: &str, quantity: i32, price: i32) -> String {
format!("{name},{quantity},{price}")
}
fn main() {
let quantity = ;
let item = ("book", quantity, 12);
let row = csv_row(item.0, item.1, item.2);
println!("{row}");
}
fn csv_row(name: &str, quantity: i32, price: i32) -> String {
format!("{name},{quantity},{price}")
}
fn main() {
let quantity = ;
let item = ("book", quantity, 12);
let row = csv_row(item.0, item.1, item.2);
println!("{row}");
}
fn csv_row(name: &str, quantity: i32, price: i32) -> String {
format!("{name},{quantity},{price}")
}
serialization
Serialization converts typed program values into a text representation.
tuple fields
`item.0`, `item.1`, and `item.2` read the record fields in order.
format!
`format!` builds the serialized row without printing immediately.