Expand description
Typed Discord snowflake IDs.
Every Discord resource is identified by a 64-bit snowflake. djs-rs represents them with a
single generic type, Id<T>, where T is a zero-sized marker describing what the ID
points at (see marker). Type aliases such as UserId and ChannelId make signatures
readable:
use djs_model::id::{ChannelId, UserId};
fn send_to(channel: ChannelId) -> u64 {
channel.get()
}
let channel = ChannelId::new(1_234_567_890_123_456_789);
assert_eq!(send_to(channel), 1_234_567_890_123_456_789);
let user = UserId::new(80_351_110_224_678_912);
// send_to(user); // ❌ does not compile: a user ID is not a channel ID§Memory layout
Id<T> wraps a NonZeroU64 (Discord never issues the ID 0), so both Id<T> and
Option<Id<T>> are exactly 8 bytes.
§Serialization
Discord transmits snowflakes as JSON strings ("80351110224678912") to avoid precision
loss in JavaScript. Id<T> serializes to a string and deserializes from either a string or an
integer.
discord.js counterpart: the Snowflake string type and SnowflakeUtil.
Modules§
Structs§
- Id
- A typed Discord snowflake ID.
- Parse
IdError - The error returned when parsing an
Idfrom a string or integer fails.
Constants§
- DISCORD_
EPOCH_ MS - The Discord epoch — the first second of 2015 — in milliseconds since the Unix epoch.
Type Aliases§
- Application
Id - ID of a resource marked by
ApplicationMarker. - Attachment
Id - ID of a resource marked by
AttachmentMarker. - Audit
LogEntry Id - ID of a resource marked by
AuditLogEntryMarker. - Auto
Moderation Rule Id - ID of a resource marked by
AutoModerationRuleMarker. - Channel
Id - ID of a resource marked by
ChannelMarker. - Command
Id - ID of a resource marked by
CommandMarker. - Command
Version Id - ID of a resource marked by
CommandVersionMarker. - EmojiId
- ID of a resource marked by
EmojiMarker. - Entitlement
Id - ID of a resource marked by
EntitlementMarker. - Generic
Id - ID of a resource marked by
GenericMarker. - GuildId
- ID of a resource marked by
GuildMarker. - Integration
Id - ID of a resource marked by
IntegrationMarker. - Interaction
Id - ID of a resource marked by
InteractionMarker. - LobbyId
- ID of a resource marked by
LobbyMarker. - Message
Id - ID of a resource marked by
MessageMarker. - RoleId
- ID of a resource marked by
RoleMarker. - Scheduled
Event Id - ID of a resource marked by
ScheduledEventMarker. - SkuId
- ID of a resource marked by
SkuMarker. - Soundboard
Sound Id - ID of a resource marked by
SoundboardSoundMarker. - Stage
Instance Id - ID of a resource marked by
StageInstanceMarker. - Sticker
Id - ID of a resource marked by
StickerMarker. - Sticker
Pack Id - ID of a resource marked by
StickerPackMarker. - Subscription
Id - ID of a resource marked by
SubscriptionMarker. - TagId
- ID of a resource marked by
TagMarker. - TeamId
- ID of a resource marked by
TeamMarker. - UserId
- ID of a resource marked by
UserMarker. - Webhook
Id - ID of a resource marked by
WebhookMarker.