diff options
| author | Leah <[email protected]> | 2018-03-23 13:54:12 +0100 |
|---|---|---|
| committer | alex <[email protected]> | 2018-03-23 13:54:12 +0100 |
| commit | fdcf44e1463e708cd8b612c183e302db9af0febd (patch) | |
| tree | 1a311f26fb38522ba380881fa6e72c0c2e5c54bc /src/model/id.rs | |
| parent | Fix Create(Embed/Message) to be consistent (diff) | |
| download | serenity-fdcf44e1463e708cd8b612c183e302db9af0febd.tar.xz serenity-fdcf44e1463e708cd8b612c183e302db9af0febd.zip | |
Change the way ids and some enums are made (#295)
This makes them easier to be found by tools like rls.
Also update struct inits to use the shorthand version for `x: x`.
Diffstat (limited to 'src/model/id.rs')
| -rw-r--r-- | src/model/id.rs | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/src/model/id.rs b/src/model/id.rs index 3d8c20c..4e2fbc3 100644 --- a/src/model/id.rs +++ b/src/model/id.rs @@ -7,13 +7,8 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use super::utils::U64Visitor; macro_rules! id_u64 { - ($(#[$attr:meta] $name:ident;)*) => { + ($($name:ident;)*) => { $( - #[$attr] - #[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] - #[allow(derive_hash_xor_eq)] - pub struct $name(pub u64); - impl $name { /// Retrieves the time that the Id was created at. pub fn created_at(&self) -> NaiveDateTime { @@ -65,25 +60,65 @@ macro_rules! id_u64 { } } +/// An identifier for an Application. +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct ApplicationId(pub u64); + +/// An identifier for a Channel +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct ChannelId(pub u64); + +/// An identifier for an Emoji +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct EmojiId(pub u64); + +/// An identifier for a Guild +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct GuildId(pub u64); + +/// An identifier for an Integration +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct IntegrationId(pub u64); + +/// An identifier for a Message +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct MessageId(pub u64); + +/// An identifier for a Role +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct RoleId(pub u64); + +/// An identifier for a User +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct UserId(pub u64); + +/// An identifier for a [`Webhook`](struct.Webhook.html). +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct WebhookId(pub u64); + +/// An identifier for an audit log entry. +#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialOrd, Ord, Serialize)] +#[allow(derive_hash_xor_eq)] +pub struct AuditLogEntryId(pub u64); + id_u64! { - /// An identifier for an Application. ApplicationId; - /// An identifier for a Channel ChannelId; - /// An identifier for an Emoji EmojiId; - /// An identifier for a Guild GuildId; - /// An identifier for an Integration IntegrationId; - /// An identifier for a Message MessageId; - /// An identifier for a Role RoleId; - /// An identifier for a User UserId; - /// An identifier for a [`Webhook`](struct.Webhook.html). WebhookId; - /// An identifier for an audit log entry. AuditLogEntryId; } |