1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 23:29:58 +00:00

AK: Implement Formatter for ErrorOr<>

As the Formatter for Error already exists, this apparently was just
accidentally omitted.
This commit is contained in:
Ben Wiederhake 2021-11-26 22:33:04 +01:00 committed by Andreas Kling
parent cf315635a8
commit dbd60f9ff4

View File

@ -624,6 +624,16 @@ struct Formatter<Error> : Formatter<FormatString> {
}
};
template<typename T, typename ErrorType>
struct Formatter<ErrorOr<T, ErrorType>> : Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, ErrorOr<T, ErrorType> const& error_or)
{
if (error_or.is_error())
return Formatter<FormatString>::format(builder, "{}", error_or.error());
return Formatter<FormatString>::format(builder, "{{{}}}", error_or.value());
}
};
} // namespace AK
#ifdef KERNEL