tadpole/types/ids
Opaque ID types so a UserId can never be passed where a GuildId goes. Every ID wraps a validated snowflake; nothing outside this module can build one from thin air or read the integer back out.
When you reach for this
Events hand you typed IDs already — message.channel_id is a
ChannelId, ready for bot.send_message — so most code never calls a
constructor. You construct when an id arrives as text: config, a
command argument, a URL. The constructor validates it as a snowflake
before it can go anywhere near Discord.
The types
UserId, GuildId, ChannelId, MessageId, RoleId, ApplicationId, WebhookId — one per Discord object kind this slice touches, all opaque, all built the same way:
import tadpole/types/ids
// "123456789012345678" -> Ok(channel id)
// "nope" -> Error(InvalidId("nope", NotANumber))
ids.channel_id("123456789012345678")
Reading back: user_to_string, user_to_int, guild_to_string,
channel_to_string, message_to_string, role_to_string — the
explicit accessors this slice needs. Missing accessors get added
when a milestone dereferences the ID, with a reason in their doc.
Failure modes
Constructors fail with InvalidId(value, reason) when the string is
not a number, is negative, or embeds a timestamp past ~2090 — see
tadpole/types/snowflake for the rules. Decoding
Discord payloads validates through the same constructors, so a
payload with a garbage id fails as DecodeFailed, not with a broken
ID in hand. Conversions cannot fail.
See also
tadpole/types/snowflake— the value underneathtadpole/model/message— typed IDs straight out of payloads
Types
pub opaque type ApplicationId
pub type InvalidId {
InvalidId(
value: String,
reason: snowflake.InvalidSnowflakeReason,
)
}
Constructors
-
InvalidId( value: String, reason: snowflake.InvalidSnowflakeReason, )
Values
pub fn application_id(
value: String,
) -> Result(ApplicationId, InvalidId)
pub fn channel_to_string(id: ChannelId) -> String
pub fn guild_to_string(id: GuildId) -> String
pub fn message_to_string(id: MessageId) -> String
pub fn role_to_string(id: RoleId) -> String
pub fn user_to_int(id: UserId) -> Int
pub fn user_to_string(id: UserId) -> String