[Enhancement] Implement format methods for Status (#26133)
This commit is contained in:
@ -612,3 +612,17 @@ using ResultError = unexpected<Status>;
|
||||
// clang-format on
|
||||
|
||||
} // namespace doris
|
||||
|
||||
// specify formatter for Status
|
||||
template <>
|
||||
struct fmt::formatter<doris::Status> {
|
||||
template <typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx) {
|
||||
return ctx.begin();
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(doris::Status const& status, FormatContext& ctx) {
|
||||
return fmt::format_to(ctx.out(), "{}", status.to_string());
|
||||
}
|
||||
};
|
||||
|
||||
@ -73,4 +73,14 @@ TEST_F(StatusTest, Error) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(StatusTest /*unused*/, Format /*unused*/) {
|
||||
// status == ok
|
||||
Status st_ok = Status::OK();
|
||||
EXPECT_TRUE(fmt::format("{}", st_ok).compare(fmt::format("{}", st_ok.to_string())) == 0);
|
||||
|
||||
// status == error
|
||||
Status st_error = Status::InternalError("123");
|
||||
EXPECT_TRUE(fmt::format("{}", st_error).compare(fmt::format("{}", st_error.to_string())) == 0);
|
||||
}
|
||||
|
||||
} // namespace doris
|
||||
|
||||
Reference in New Issue
Block a user