tadpole/types/snowflake
Snowflakes: Discord’s 64-bit IDs. The top 42 bits embed the creation time in milliseconds since the Discord epoch (2015-01-01); the low bits are worker and sequence noise. Every Discord object id is one.
Internals: most code meets snowflakes through the opaque wrappers in
tadpole/types/ids. Come here for the raw value,
validation, or the timestamp — sorting by age (older id = earlier
creation) and dating objects without a timestamp field are the usual
reasons.
let assert Ok(id) = snowflake.from_string("123456789012345678")
snowflake.timestamp_ms(id) // unix ms of creation
Validation rejects negatives and values whose embedded timestamp
exceeds ~2090 (TooFarInFuture) — corrupted data, not a real id.
Everything else here cannot fail.
Types
pub type InvalidSnowflake {
InvalidSnowflake(value: String, reason: InvalidSnowflakeReason)
}
Constructors
-
InvalidSnowflake(value: String, reason: InvalidSnowflakeReason)
pub type InvalidSnowflakeReason {
NotANumber
NegativeValue
TooFarInFuture
}
Constructors
-
NotANumber -
NegativeValue -
TooFarInFuture
Values
pub const discord_epoch: Int
pub fn from_int(
value: Int,
) -> Result(Snowflake, InvalidSnowflake)
Validates the embedded timestamp window; rejects negatives.
pub fn from_string(
value: String,
) -> Result(Snowflake, InvalidSnowflake)
pub const max_inner_timestamp: Int
Rejects timestamps past ~2090 as corrupted.
pub fn timestamp_ms(snowflake: Snowflake) -> Int
Creation time in unix milliseconds.
pub fn to_int(snowflake: Snowflake) -> Int
IDs travel as strings in JSON; this is internal plumbing.