rust-csv
rust-csv copied to clipboard
Question about (de)serializing vectors
Hi, thanks for providing this great crate. Currently, when I am using the crate to serialise a vector inside a struct it will be flattened, so say I have:
struct A { a : String, b : Vec<i64> }
and I have a flexible writer, then two As {"Hello",[1,2,3]}, {"Bye", [4,5,6,7]} would be serialized to "Hello", 1,2,3, "Bye", 4,5,6,7
Is there any way I can tell the CSV writer to serialize it to "Hello", [1,2,3] "Bye", [4,5,6,7] ?
Please provide a complete Rust program, any relevant inputs, actual output and desired output.
Program
use std::io; use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug)]
struct A {
a: String,
b: Vec
fn main() { let x = A { a: "Hello".to_string(), b: vec![1, 2, 3] }; let y = A { a: "Bye".to_string(), b: vec![4, 5, 6, 7] }; let mut w = csv::WriterBuilder::new() .flexible(true).has_headers(false).from_writer(io::stdout()); w.serialize(x); w.serialize(y); }
Actual output Hello,1,2,3 Bye,4,5,6,7 Desired output Hello,[1,2,3] Bye,[4,5,6,7]