title: get structure header names with serde Serialize preserving order
body: <p>Rust data structure.</p>
  <p>This is my implementation to get headers preserving order:</p>
  <pre><code>use serde::{Deserialize, Serialize};
  use csv::{Reader, Writer, StringRecord};
  
  #[derive(Default, Debug, Deserialize, Serialize)]
  pub struct Colunas {
      #[serde(rename = &quot;Arquivo Teste&quot;)]
      arquivo: String,
      #[serde(rename = &quot;CNPJ dos Estabelecimentos&quot;)]
      cnpj: Option&lt;String&gt;,
      #[serde(rename = &quot;Ano do Período de Apuração&quot;)]
      ano: Option&lt;usize&gt;,
      #[serde(rename = &quot;Mês&quot;)]
      m: u32,
  }
  
  impl Colunas {
      fn get_headers(self) -&gt; StringRecord {
          // https://docs.rs/csv/1.0.0/csv/struct.Writer.html
          let mut wtr = Writer::from_writer(vec![]);
          wtr.serialize( Colunas::default() ).ok();
          
          let colunas = String::from_utf8(wtr.into_inner().ok().unwrap()).ok().unwrap();
          
          // split-a-string-in-rust
          let mut lines = colunas.lines();
          let first_line = lines.next().unwrap();
          //println!(&quot;first_line: {:#?}&quot;, &amp;first_line);
          
          let vec: Vec&lt;&amp;str&gt; = first_line.split(',').collect();
          //println!(&quot;vec: {:#?}&quot;, vec);
          
          //https://docs.rs/csv/1.0.0-beta.2/csv/struct.StringRecord.html
          // https://docs.rs/csv/1.0.0/csv/struct.Reader.html
          let mut rdr = Reader::from_reader(&quot;&quot;.as_bytes());
          rdr.set_headers(StringRecord::from(vec));
          
          let headers = rdr.headers().ok().unwrap();
          //println!(&quot;headers: {:#?}&quot;, headers);
          
          headers.clone()
      }
  }
  
  fn main() {
      let headers = Colunas::default().get_headers();
      println!(&quot;headers: {:#?}&quot;, headers);
  }
  </code></pre>
  <p>Is there any other more elegant and concise way?</p>
  <p>Rust playground:
  <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=24cd9eeed8f5fbfa2abf0eff467a03a2" rel="nofollow noreferrer">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2021&amp;gist=24cd9eeed8f5fbfa2abf0eff467a03a2</a></p>
  <p>The output is:</p>
  <p>headers: StringRecord([&quot;Arquivo Teste&quot;, &quot;CNPJ dos Estabelecimentos&quot;, &quot;Ano do Período de Apuração&quot;, &quot;Mês&quot;])</p>