From 4a113c68a7d1eb607ae57f9f5fba8f71c3e9fd92 Mon Sep 17 00:00:00 2001 From: Miuna <809711+Mishura4@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:56:53 -0400 Subject: [PATCH] fix: make snowflake formattable again (#943) --- include/dpp/snowflake.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/dpp/snowflake.h b/include/dpp/snowflake.h index f6739a4bc0..a2c5496625 100644 --- a/include/dpp/snowflake.h +++ b/include/dpp/snowflake.h @@ -251,6 +251,18 @@ class DPP_EXPORT snowflake final { constexpr uint16_t get_increment() const noexcept { return static_cast(value & 0xFFF); } + + /** + * @brief Helper function for libfmt so that a snowflake can be directly formatted as a uint64_t. + * + * @see https://fmt.dev/latest/api.html#formatting-user-defined-types + * @return uint64_t snowflake ID + */ + friend constexpr uint64_t format_as(snowflake s) noexcept { + /* note: this function must stay as "friend" - this declares it as a free function but makes it invisible unless the argument is snowflake + * this effectively means no implicit conversions are performed to snowflake, for example format_as(0) doesn't call this function */ + return s.value; + } }; } // namespace dpp