mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +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
|
} // namespace AK
|
||||||
|
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
|
|
Loading…
Reference in a new issue