From ad6ebfccfc89c318ba5570676c75a20821b51044 Mon Sep 17 00:00:00 2001 From: Amber Ehrlich Date: Wed, 11 Oct 2023 12:13:30 -0400 Subject: [PATCH] feat: make snowflake formattable again --- 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