Expand description

ID with type-safe markers for each resource.

When IDs are simple 64-bit integers then it may be easy to accidentally use the ID of a role in place of where one means to use the ID of a user. This is a programmatic error; it’s on the programmer to notice. By using IDs with typed markers, it can be ensured that only an ID with a guild marker is used where an ID with a guild marker is requested.

Parsing

IDs may be initialized or parsed in a variety of manners depending on the context:

Casting between resource types

Discord may have constraints where IDs are the same across resources. For example, the @everyone role of a guild has the same ID as the guild itself. In this case, all one needs to do is use the guild’s ID in place of a role in order to operate on the @everyone role of the guild. IDs can be easily casted in order to fulfill this:

use twilight_model::id::{
    marker::{GuildMarker, RoleMarker},
    Id,
};

// Often Rust's type inference will be able to infer the type of ID.
let guild_id = Id::<GuildMarker>::new(123);
let role_id = guild_id.cast::<RoleMarker>();

assert_eq!(guild_id.get(), role_id.get());

Modules

Markers for various resource types, such as channels or users.

Structs

ID of a resource, such as the ID of a channel or user.

Type Definitions

ApplicationIdDeprecated

ID with an application marker.

AttachmentIdDeprecated

ID with an attachment marker.

AuditLogEntryIdDeprecated

ID with an audit log entry marker.

ChannelIdDeprecated

ID with a channel marker.

CommandIdDeprecated

ID with a command marker.

ID with a command marker.

EmojiIdDeprecated

ID with an emoji marker.

GenericIdDeprecated

ID with a generic marker.

GuildIdDeprecated

ID with a guild marker.

IntegrationIdDeprecated

ID with an integration marker.

InteractionIdDeprecated

ID with an interaction marker.

MessageIdDeprecated

ID with a message marker.

OauthSkuIdDeprecated

ID with an OAuth SKU marker.

OauthTeamIdDeprecated

ID with an OAuth team marker.

RoleIdDeprecated

ID with a role marker.

StageIdDeprecated

ID with a stage marker.

ID with a sticker banner asset marker.

StickerIdDeprecated

ID with a sticker marker.

StickerPackIdDeprecated

ID with a sticker pack marker.

ID with a sticker pack SKU marker.

UserIdDeprecated

ID with a user marker.

WebhookIdDeprecated

ID with a webhook marker.