Minor snowflake updates (#179)
* Make snowflake fully public * Simple into for snowflake
This commit is contained in:
parent
b6ab9d47ad
commit
855a4278df
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue