-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
How to use serde::format_description
with format_description::well_known
?
#676
Comments
What feature flags do you have enabled? |
I use: |
That can't be the case, as Have you looked at the documentation for this macro? The final example shows how to use it with ISO 8601. |
Ok, here is my test case.
[dependencies]
serde = { version = "1.0.198", features = ["derive"] }
time = { version = "0.3.36", features = ["formatting", "macros", "parsing", "serde"] }
[dev-dependencies]
serde_json = { version = "1.0.116" }
use time::{
format_description::well_known::{iso8601, Iso8601},
serde::format_description,
OffsetDateTime,
};
const CONFIG: iso8601::EncodedConfig = iso8601::Config::DEFAULT
.set_formatted_components(iso8601::FormattedComponents::DateTime)
.encode();
const FORMAT: Iso8601<CONFIG> = Iso8601::<CONFIG>;
format_description!(serde_datetime, OffsetDateTime, FORMAT);
#[derive(serde::Deserialize, Debug, PartialEq)]
pub struct Container {
#[serde(with="serde_datetime")]
pub datetime: OffsetDateTime,
}
use time::{
Date,
Month,
OffsetDateTime,
Time,
};
#[test]
fn without_offset() {
let json = serde_json::json!({
"datetime": "2024-04-17T12:45:00.0"
});
let actual: Container = serde_json::from_value(json).unwrap();
assert_eq!(
actual,
Container {
datetime: OffsetDateTime::new_utc(
Date::from_calendar_date(2024, Month::April, 17).unwrap(),
Time::from_hms(12, 45, 0).unwrap(),
),
},
);
} Then, I got:
Worth to mention that error isn't very explicit :/ |
The failure is as expected, as there is no I will look into what can be done in terms of an error message, but I suspect there isn't much. |
I wanna map "non-offset" strings against
OffsetDatetime
.I tried (sorry not provided Rust Playground links, but seems it lacks some features):
But I get following errors:
Trying to replace
Iso8601.DATE_TIME
withIso8601::DATE_TIME
, blocks macro evaluation:The text was updated successfully, but these errors were encountered: