Minor snowflake updates (#179)

* Make snowflake fully public

* Simple into for snowflake
This commit is contained in:
kozabrada123 2023-08-07 18:34:58 +00:00 committed by GitHub
parent 2d7fe96eda
commit 1801d22273
1 changed files with 10 additions and 1 deletions

View File

@ -17,7 +17,7 @@ const EPOCH: i64 = 1420070400000;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "sqlx", derive(Type))] #[cfg_attr(feature = "sqlx", derive(Type))]
#[cfg_attr(feature = "sqlx", sqlx(transparent))] #[cfg_attr(feature = "sqlx", sqlx(transparent))]
pub struct Snowflake(u64); pub struct Snowflake(pub u64);
impl Snowflake { impl Snowflake {
/// Generates a snowflake for the current timestamp, with worker id 0 and process id 1. /// Generates a snowflake for the current timestamp, with worker id 0 and process id 1.
@ -53,6 +53,15 @@ impl Display for Snowflake {
} }
} }
impl<T> From<T> for Snowflake
where
T: Into<u64>,
{
fn from(item: T) -> Self {
Self(item.into())
}
}
impl serde::Serialize for Snowflake { impl serde::Serialize for Snowflake {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where where