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

Unable to provide #[serde( with = )] instructions #615

Open
fnordpig opened this issue Feb 9, 2023 · 0 comments
Open

Unable to provide #[serde( with = )] instructions #615

fnordpig opened this issue Feb 9, 2023 · 0 comments

Comments

@fnordpig
Copy link

fnordpig commented Feb 9, 2023

When trying to deserialize/serialize something with a custom handler for a field in a struct that needs to be handled by serde (specifically in my case chrono::DateTime encoded with ts_milliseconds), it doesn't work. I had to wrap my DateTime<> members in a wrapper struct that I wrote. Not doing this causes huge performance problems as the default encoding / decoding is string based.

I can provide a working example if desired, but here's a snippet from my code reflecting my workaround:

#[derive(PartialEq, Debug, Serialize, Deserialize, Clone)]
pub struct DateTimeWrapper {
    #[serde(with = "ts_milliseconds")]
    pub time: DateTime<Utc>,
}


#[derive(Debug, Clone, PartialEq,  bincode::Decode, bincode::Encode)]
pub struct Quote {
    #[bincode(with_serde)]
    pub time: DateTimeWrapper,
    pub price: f64,
    pub size: f64
}

I would much rather it be:

#[derive(Debug, Clone, PartialEq,  bincode::Decode, bincode::Encode)]
pub struct Quote {
    #[bincode(with_serde)]
    #[serde(with = "ts_milliseconds")]
    pub time: DateTime<Utc>,
    pub price: f64,
    pub size: f64
}

Thank you for the excellent project by the way, I love the 2.0 can't wait to see it release.

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

No branches or pull requests

2 participants