Skip to content

UTC_OFFSET_FORMAT: use const blocks around function calls #704

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

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions time/src/serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
])),
])),
];
Expand Down