diff --git a/clustering_bounds_comparator.hh b/clustering_bounds_comparator.hh index 353ca017c2..c0d2ed3e4c 100644 --- a/clustering_bounds_comparator.hh +++ b/clustering_bounds_comparator.hh @@ -153,6 +153,7 @@ public: return {typename R::bound(bv._prefix.get().view(), inclusive)}; } friend std::ostream& operator<<(std::ostream& out, const bound_view& b) { - return out << "{bound: prefix=" << b._prefix.get() << ", kind=" << b._kind << "}"; + fmt::print(out, "{{bound: prefix={}, kind={}}}", b._prefix.get(), b._kind); + return out; } }; diff --git a/utils/managed_bytes.cc b/utils/managed_bytes.cc index 51ebb04f0c..577bb54f0e 100644 --- a/utils/managed_bytes.cc +++ b/utils/managed_bytes.cc @@ -28,16 +28,9 @@ managed_bytes_opt to_managed_bytes_opt(const bytes_opt& bo) { } sstring to_hex(const managed_bytes& b) { - return fmt::to_string(managed_bytes_view(b)); + return seastar::format("{}", managed_bytes_view(b)); } sstring to_hex(const managed_bytes_opt& b) { return !b ? "null" : to_hex(*b); } - -std::ostream& operator<<(std::ostream& os, const managed_bytes_opt& b) { - if (b) { - return os << *b; - } - return os << "null"; -} diff --git a/utils/managed_bytes.hh b/utils/managed_bytes.hh index 7d77e02d5b..e28a7898df 100644 --- a/utils/managed_bytes.hh +++ b/utils/managed_bytes.hh @@ -591,15 +591,36 @@ struct hash { sstring to_hex(const managed_bytes& b); sstring to_hex(const managed_bytes_opt& b); -// The operators below are used only by tests. - -inline std::ostream& operator<<(std::ostream& os, const managed_bytes_view& v) { - for (bytes_view frag : fragment_range(v)) { - os << to_hex(frag); +// The formatters below are used only by tests. +template <> struct fmt::formatter : fmt::formatter { + auto format(const managed_bytes_view& v, fmt::format_context& ctx) const { + auto out = ctx.out(); + for (bytes_view frag : fragment_range(v)) { + out = fmt::format_to(out, "{}", fmt_hex(frag)); + } + return out; } +}; +inline std::ostream& operator<<(std::ostream& os, const managed_bytes_view& v) { + fmt::print(os, "{}", v); return os; } + +template <> struct fmt::formatter : fmt::formatter { + auto format(const managed_bytes& b, fmt::format_context& ctx) const { + return fmt::format_to(ctx.out(), "{}", managed_bytes_view(b)); + } +}; inline std::ostream& operator<<(std::ostream& os, const managed_bytes& b) { - return (os << managed_bytes_view(b)); + fmt::print(os, "{}", b); + return os; } -std::ostream& operator<<(std::ostream& os, const managed_bytes_opt& b); + +template <> struct fmt::formatter : fmt::formatter { + auto format(const managed_bytes_opt& opt, fmt::format_context& ctx) const { + if (opt) { + return fmt::format_to(ctx.out(), "{}", *opt); + } + return fmt::format_to(ctx.out(), "null"); + } +};