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