Skip to main content

Module id

Module id 

Source
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§

marker
Marker types for Id.

Structs§

Id
A typed Discord snowflake ID.
ParseIdError
The error returned when parsing an Id from 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§

ApplicationId
ID of a resource marked by ApplicationMarker.
AttachmentId
ID of a resource marked by AttachmentMarker.
AuditLogEntryId
ID of a resource marked by AuditLogEntryMarker.
AutoModerationRuleId
ID of a resource marked by AutoModerationRuleMarker.
ChannelId
ID of a resource marked by ChannelMarker.
CommandId
ID of a resource marked by CommandMarker.
CommandVersionId
ID of a resource marked by CommandVersionMarker.
EmojiId
ID of a resource marked by EmojiMarker.
EntitlementId
ID of a resource marked by EntitlementMarker.
GenericId
ID of a resource marked by GenericMarker.
GuildId
ID of a resource marked by GuildMarker.
IntegrationId
ID of a resource marked by IntegrationMarker.
InteractionId
ID of a resource marked by InteractionMarker.
LobbyId
ID of a resource marked by LobbyMarker.
MessageId
ID of a resource marked by MessageMarker.
RoleId
ID of a resource marked by RoleMarker.
ScheduledEventId
ID of a resource marked by ScheduledEventMarker.
SkuId
ID of a resource marked by SkuMarker.
SoundboardSoundId
ID of a resource marked by SoundboardSoundMarker.
StageInstanceId
ID of a resource marked by StageInstanceMarker.
StickerId
ID of a resource marked by StickerMarker.
StickerPackId
ID of a resource marked by StickerPackMarker.
SubscriptionId
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.
WebhookId
ID of a resource marked by WebhookMarker.