jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
250 stars 23 forks source link

feature request: Could serialize_chrono_naive_to_excel() accept Option<T>? #62

Closed claudiofsr closed 7 months ago

claudiofsr commented 7 months ago

Feature Request

Hi!!!

Please see: https://github.com/claudiofsr/read_xml/blob/master/src/excel.rs https://github.com/claudiofsr/read_xml/blob/master/src/xml_structs/efinanceira.rs

I have:

#[derive(Debug, Default, Serialize, Deserialize, Clone)]
pub struct InfoEFinanceira {
   ...
    #[serde(rename = "Ano/Mês Caixa Reportado")]
    pub ano_mes_caixa: Option<NaiveDate>,
   ...
    #[serde(rename = "Balanço da Conta: Total de Débitos")]
    pub tot_debitos: f64,
}

I try use

#[serde(rename = "Ano/Mês Caixa Reportado", serialize_with = "serialize_chrono_naive_to_excel")]

but I have ano_mes_caixa: Option<NaiveDate>.

Could serialize_chrono_naive_to_excel() accept Option<T>?

Thanks.

jmcnamara commented 7 months ago

Could serialize_chrono_naive_to_excel() accept Option<T>?

Yes. Or at least I can add a second function to do Option<T>. Would that work for you?

claudiofsr commented 7 months ago

Both possibilities are good!

Thanks.

jmcnamara commented 7 months ago

Both possibilities are good!

I may implement both but as a first pass I implemented the second option and added a serialize_chrono_option_naive_to_excel function.

Can you try that in your use case and let me know how you get on.

claudiofsr commented 7 months ago

I tested it with my data and serialize_chrono_option_naive_to_excel worked perfectly.

Thanks!!!

jmcnamara commented 7 months ago

This is upstream in Cargo in v0.53.0. Thanks for the suggestion and testing.