From 84a9d2fa45aeff1366c38b686c5fe26ec995fc9d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 17 Jan 2024 10:33:01 +0800 Subject: [PATCH] add formatter for auth::role_or_anonymous before this change, we rely on the default-generated fmt::formatter created from operator<<, but fmt v10 dropped the default-generated formatter. in this change, we define a formatter for auth::role_or_anonymous, and remove their operator<<(). Refs #13245 Signed-off-by: Kefu Chai Closes scylladb/scylladb#16812 --- auth/role_or_anonymous.cc | 7 +++++-- auth/role_or_anonymous.hh | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/auth/role_or_anonymous.cc b/auth/role_or_anonymous.cc index 8272c39303..8e6db13466 100644 --- a/auth/role_or_anonymous.cc +++ b/auth/role_or_anonymous.cc @@ -8,8 +8,6 @@ #include "auth/role_or_anonymous.hh" -#include - namespace auth { std::ostream& operator<<(std::ostream& os, const role_or_anonymous& mr) { @@ -22,3 +20,8 @@ bool is_anonymous(const role_or_anonymous& mr) noexcept { } } + +auto fmt::formatter::format(const auth::role_or_anonymous& mr, + fmt::format_context& ctx) const -> decltype(ctx.out()) { + return fmt::format_to(ctx.out(), "{}", mr.name.value_or("")); +} diff --git a/auth/role_or_anonymous.hh b/auth/role_or_anonymous.hh index 01add54151..7015ff2589 100644 --- a/auth/role_or_anonymous.hh +++ b/auth/role_or_anonymous.hh @@ -10,8 +10,8 @@ #include #include -#include #include +#include #include @@ -29,8 +29,6 @@ public: friend bool operator==(const role_or_anonymous&, const role_or_anonymous&) noexcept = default; }; -std::ostream& operator<<(std::ostream&, const role_or_anonymous&); - bool is_anonymous(const role_or_anonymous&) noexcept; } @@ -45,3 +43,8 @@ struct hash { }; } + +template <> struct fmt::formatter { + constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } + auto format(const auth::role_or_anonymous&, fmt::format_context& ctx) const -> decltype(ctx.out()); +};