Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jrozner opened this issue Aug 24, 2021 · 0 comments
Open

Comments

@jrozner
Copy link

jrozner commented Aug 24, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant