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
Notes:
sideshowbarker
2024-07-17 23:08:03 +09:00
Author: https://github.com/BenWiederhake Commit: https://github.com/SerenityOS/serenity/commit/dbd60f9ff40 Pull-request: https://github.com/SerenityOS/serenity/pull/11113 Reviewed-by: https://github.com/BertalanD Reviewed-by: https://github.com/IdanHo Reviewed-by: https://github.com/creator1creeper1
1 changed files with 10 additions and 0 deletions
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…
Add table
Reference in a new issue