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()); +};