mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-04 15:09:40 +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:
parent
cf315635a8
commit
dbd60f9ff4
10
AK/Format.h
10
AK/Format.h
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue