Skip to content

Commit 34426ab

Browse files
committed
UTC_OFFSET_FORMAT: do not rely on promotion of function calls
1 parent f22bced commit 34426ab

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

time/src/serde/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,24 @@ impl<'a> Deserialize<'a> for Time {
406406
// region: UtcOffset
407407
/// The format used when serializing and deserializing a human-readable `UtcOffset`.
408408
#[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();
418+
#[cfg(feature = "parsing")]
409419
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-
})),
420+
BorrowedFormatItem::Component(Component::OffsetHour(UTC_OFFSET_HOUR)),
415421
BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[
416422
BorrowedFormatItem::Literal(b":"),
417-
BorrowedFormatItem::Component(Component::OffsetMinute(modifier::OffsetMinute::default())),
423+
BorrowedFormatItem::Component(Component::OffsetMinute(UTC_OFFSET_MINUTE)),
418424
BorrowedFormatItem::Optional(&BorrowedFormatItem::Compound(&[
419425
BorrowedFormatItem::Literal(b":"),
420-
BorrowedFormatItem::Component(Component::OffsetSecond(
421-
modifier::OffsetSecond::default(),
422-
)),
426+
BorrowedFormatItem::Component(Component::OffsetSecond(UTC_OFFSET_SECOND)),
423427
])),
424428
])),
425429
];

0 commit comments

Comments
 (0)