mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:57:34 +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
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
|
} // namespace AK
|
||||||
|
|
||||||
#ifdef KERNEL
|
#ifdef KERNEL
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue