From 2e68a36abc0d8cdc12638c0ed47b80cc9c07b7ab Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 6 Sep 2024 08:51:06 +0200 Subject: [PATCH] UTC_OFFSET_FORMAT: do not rely on promotion of function calls (#704) --- time/src/serde/mod.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/time/src/serde/mod.rs b/time/src/serde/mod.rs index 40caa2888..5cc5122c9 100644 --- a/time/src/serde/mod.rs +++ b/time/src/serde/mod.rs @@ -404,22 +404,27 @@ impl<'a> Deserialize<'a> for Time { // endregion Time // region: UtcOffset +// FIXME: turn these constants into `const { ... }` blocks once we can depend on Rust 1.79. +#[cfg(feature = "parsing")] +const UTC_OFFSET_HOUR: modifier::OffsetHour = { + let mut m = modifier::OffsetHour::default(); + m.sign_is_mandatory = true; + m +}; +#[cfg(feature = "parsing")] +const UTC_OFFSET_MINUTE: modifier::OffsetMinute = modifier::OffsetMinute::default(); +#[cfg(feature = "parsing")] +const UTC_OFFSET_SECOND: modifier::OffsetSecond = modifier::OffsetSecond::default(); /// The format used when serializing and deserializing a human-readable `UtcOffset`. #[cfg(feature = "parsing")] const UTC_OFFSET_FORMAT: &[BorrowedFormatItem<'_>] = &[ - BorrowedFormatItem::Component(Component::OffsetHour({ - let mut m = modifier::OffsetHour::default(); - m.sign_is_mandatory = true; - m - })), + BorrowedFormatItem::Component(Component::OffsetHour(UTC_OFFSET_HOUR)), BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[ BorrowedFormatItem::Literal(b":"), - BorrowedFormatItem::Component(Component::OffsetMinute(modifier::OffsetMinute::default())), + BorrowedFormatItem::Component(Component::OffsetMinute(UTC_OFFSET_MINUTE)), BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[ BorrowedFormatItem::Literal(b":"), - BorrowedFormatItem::Component(Component::OffsetSecond( - modifier::OffsetSecond::default(), - )), + BorrowedFormatItem::Component(Component::OffsetSecond(UTC_OFFSET_SECOND)), ])), ])), ];