Skip to content

Commit 2e68a36

Browse files
authored
UTC_OFFSET_FORMAT: do not rely on promotion of function calls (#704)
1 parent f22bced commit 2e68a36

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

time/src/serde/mod.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,27 @@ impl<'a> Deserialize<'a> for Time {
404404
// endregion Time
405405

406406
// region: UtcOffset
407+
// FIXME: turn these constants into `const { ... }` blocks once we can depend on Rust 1.79.
408+
#[cfg(feature = "parsing")]
409+
const UTC_OFFSET_HOUR: modifier::OffsetHour = {
410+
let mut m = modifier::OffsetHour::default();
411+
m.sign_is_mandatory = true;
412+
m
413+
};
414+
#[cfg(feature = "parsing")]
415+
const UTC_OFFSET_MINUTE: modifier::OffsetMinute = modifier::OffsetMinute::default();
416+
#[cfg(feature = "parsing")]
417+
const UTC_OFFSET_SECOND: modifier::OffsetSecond = modifier::OffsetSecond::default();
407418
/// The format used when serializing and deserializing a human-readable `UtcOffset`.
408419
#[cfg(feature = "parsing")]
409420
const UTC_OFFSET_FORMAT: &[BorrowedFormatItem<'_>] = &[
410-
BorrowedFormatItem::Component(Component::OffsetHour({
411-
let mut m = modifier::OffsetHour::default();
412-
m.sign_is_mandatory = true;
413-
m
414-
})),
421+
BorrowedFormatItem::Component(Component::OffsetHour(UTC_OFFSET_HOUR)),
415422
BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[
416423
BorrowedFormatItem::Literal(b":"),
417-
BorrowedFormatItem::Component(Component::OffsetMinute(modifier::OffsetMinute::default())),
424+
BorrowedFormatItem::Component(Component::OffsetMinute(UTC_OFFSET_MINUTE)),
418425
BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[
419426
BorrowedFormatItem::Literal(b":"),
420-
BorrowedFormatItem::Component(Component::OffsetSecond(
421-
modifier::OffsetSecond::default(),
422-
)),
427+
BorrowedFormatItem::Component(Component::OffsetSecond(UTC_OFFSET_SECOND)),
423428
])),
424429
])),
425430
];

0 commit comments

Comments
 (0)