Open ModProg opened 1 year ago
The problem is having a compatible data model. We are either blocked on serde
defining one or "the ecosystem" (e.g. time
and chrono
) agreeing on one. Seeing as time
defines several different data models for you to choose from, I don't have much confidence in this.
Would one way be to provide a parser that can be used with serde(with = "toml::chrono::date")
?
This could also easily be put behind a chrono
feature flag.
Alternatively, implementing From <toml::value::Date> for chrono::NaiveDate
would allow using it with the FromInto
adapter from serde_with
. (Also put behind a chrono
feature flag.
Though that would necessitate another crate on top of serde to use easily.
Or add a wrapper type toml::chrono::NaiveDate
that implements Deserialize and allows to be converted.
I would rather not have chrono
or time
in the public API.
Well I guess it would be possible to create a dedicated crate for supporting this usecase, as I guess chrono
would also not be in favor of adding a toml
module to their crate.
And changing the deserialization for chrono
and time
would probably be a breaking change for them. With it mostly being just to support toml I wouldn't expect them to do that.
But it seems a bit superfluous to have a toml_(serde_)date
crate.
Well I wrote said crate: https://github.com/ModProg/toml-datetime-compat
Maybe I just missed something, but AFAICT there is no easy way to derive serde::Deserialize on a struct and without adding helper functions get a
chrono::NaiveDate
out the other side except using string values.e.g. get from this:
to
For now the only way to do so seems to be to use
toml::value::Datetime
and afterwards ensure that it is only a local date and convert that to a NaiveDate by creating it manually.