diff options
author | MacDue <macdue@dueutil.tech> | 2023-04-18 18:31:00 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-28 09:42:28 +0200 |
commit | 454ecf24ea90057666d0e75e4473e7f6d551a985 (patch) | |
tree | 65f0a09b131831b00a651637353177be0164dce3 /AK | |
parent | fc1fd907b4fa21331a2f6b364b5fff351bf513a3 (diff) | |
download | serenity-454ecf24ea90057666d0e75e4473e7f6d551a985.zip |
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.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Format.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/AK/Format.h b/AK/Format.h index 42e2a67a25..1766e510d1 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -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 |