rust-csv icon indicating copy to clipboard operation
rust-csv copied to clipboard

Provide a way to serialize the header prefixed with a comment character

Open jrozner opened this issue 4 years ago • 0 comments

What version of the csv crate are you using?

1.1.6

Briefly describe the question, bug or feature request.

Serialize the header prefixed with a comment character (eg. '#')

Include a complete program demonstrating a problem.

use std::fs::File;
use std::io::Write;

use serde::Serialize;

#[derive(Debug, Clone, Serialize)]
pub struct Partition {
    name: String,
    #[serde(rename="type")]
    partition_type: u32,
    subtype: u32,
    offset: u32,
    size: u32,
    flags: u32,
}

fn main() {
    let partitions = vec![
        Partition {
            name: "test".to_owned(),
            partition_type: 1,
            subtype: 1,
            offset: 1,
            size: 1,
            flags: 1,
        },
        Partition {
            name: "test2".to_owned(),
            partition_type: 1,
            subtype: 1,
            offset: 1,
            size: 1,
            flags: 1,
        },
    ];
    let mut wrt = csv::Writer::from_writer(std::io::stdout());
    partitions.iter().for_each(|partition| wrt.serialize(partition).unwrap());
    wrt.flush().unwrap();
}

What is the observed behavior of the code above?

name,type,subtype,offset,size,flags

What is the expected or desired behavior of the code above?

#name,type,subtype,offset,size,flags

jrozner avatar Aug 24 '21 03:08 jrozner