AK: Make the Optional formatter always available and tweak its format

There's no real reason to make this a debug-only formatter, on top of
that, jakt has a optional formatter that prints None/foo instead of
OptionalNone/Optional(foo), which is more concise anyway, so switch to
that.
This commit is contained in:
Ali Mohammad Pur 2023-04-28 14:03:44 +03:30 committed by Andreas Kling
parent 8ff6239d4f
commit 41cf52a623
Notes: sideshowbarker 2024-07-17 07:06:47 +09:00

View file

@ -717,13 +717,11 @@ 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);
return Formatter<FormatString>::format(builder, "{}"sv, *optional);
return builder.put_literal("None"sv);
}
};