1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 17:57:35 +00:00

AK+LibTimeZone: Add debug only formatter for Optional

I found this handy for debugging, and so might others.

This now also adds a formatter for TimeZone::TimeZone. This is needed
for FormatIfSupported<Optional<TimeZone::TimeZone>> to compile. As
FormatIfSupported sees a formatter for Optional exists, but not that
there's not one for TimeZone::TimeZone.
This commit is contained in:
MacDue 2023-04-18 18:31:00 +01:00 committed by Andreas Kling
parent fc1fd907b4
commit 454ecf24ea
2 changed files with 21 additions and 0 deletions

View file

@ -715,6 +715,18 @@ struct Formatter<ErrorOr<T, ErrorType>> : Formatter<FormatString> {
}
};
template<typename T>
struct Formatter<Optional<T>> : Formatter<FormatString> {
static constexpr bool is_debug_only() { return true; }
ErrorOr<void> format(FormatBuilder& builder, Optional<T> const& optional)
{
if (optional.has_value())
return Formatter<FormatString>::format(builder, "Optional({})"sv, *optional);
return builder.put_literal("OptionalNone"sv);
}
};
} // namespace AK
#if USING_AK_GLOBALLY