From 855a4278df8490a623803c8b19a93d35890199dd Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:34:58 +0000 Subject: [PATCH] Minor snowflake updates (#179) * Make snowflake fully public * Simple into for snowflake --- src/types/utils/snowflake.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/types/utils/snowflake.rs b/src/types/utils/snowflake.rs index a9f572b..b4e1d9e 100644 --- a/src/types/utils/snowflake.rs +++ b/src/types/utils/snowflake.rs @@ -17,7 +17,7 @@ const EPOCH: i64 = 1420070400000; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[cfg_attr(feature = "sqlx", derive(Type))] #[cfg_attr(feature = "sqlx", sqlx(transparent))] -pub struct Snowflake(u64); +pub struct Snowflake(pub u64); impl Snowflake { /// Generates a snowflake for the current timestamp, with worker id 0 and process id 1. @@ -53,6 +53,15 @@ impl Display for Snowflake { } } +impl From for Snowflake +where + T: Into, +{ + fn from(item: T) -> Self { + Self(item.into()) + } +} + impl serde::Serialize for Snowflake { fn serialize(&self, serializer: S) -> Result where