From b8e17d03ce936a97e6bb249020139b93d5d3ee16 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Wed, 19 Jan 2022 18:55:15 -0500 Subject: [PATCH 1/3] refactor(model)!: revert moving snowflake to model Revert "refactor: add snowflake getters to `Id` (#1332)", effectively moving the `Snowflake` trait back to `util`. The Snowflake trait isn't a model, it's a helper for some computations; the model crate otherwise has no other traits other than this one, and so it's unprecedented and its addition was a mistake. This reverts commit 540ee9a8e9e4127c1744692a49b50dbac99c2d7d. --- model/src/id/marker.rs | 91 --------------- model/src/id/mod.rs | 141 +++-------------------- util/Cargo.toml | 5 +- util/README.md | 5 + util/src/lib.rs | 9 ++ util/src/snowflake.rs | 250 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 285 insertions(+), 216 deletions(-) create mode 100644 util/src/snowflake.rs diff --git a/model/src/id/marker.rs b/model/src/id/marker.rs index cba802fe1e1..1f21d8adb4a 100644 --- a/model/src/id/marker.rs +++ b/model/src/id/marker.rs @@ -237,94 +237,3 @@ pub struct UserMarker; #[derive(Clone, Copy, Debug)] #[non_exhaustive] pub struct WebhookMarker; - -/// Snowflake marker trait. -/// -/// A snowflake is a globally unique ID made up of a timestamp, worker ID, process ID and increment. -/// Types implementing this trait enable methods for extracting this information from [`Id`]s. -/// -/// [`Id`]: super::Id -pub trait Snowflake: private::Sealed {} - -impl Snowflake for ApplicationMarker {} - -impl Snowflake for AttachmentMarker {} - -impl Snowflake for AuditLogEntryMarker {} - -impl Snowflake for ChannelMarker {} - -impl Snowflake for CommandMarker {} - -impl Snowflake for CommandVersionMarker {} - -impl Snowflake for EmojiMarker {} - -impl Snowflake for GenericMarker {} - -impl Snowflake for GuildMarker {} - -impl Snowflake for IntegrationMarker {} - -impl Snowflake for InteractionMarker {} - -impl Snowflake for MessageMarker {} - -impl Snowflake for RoleMarker {} - -impl Snowflake for ScheduledEventMarker {} - -impl Snowflake for ScheduledEventEntityMarker {} - -impl Snowflake for StageMarker {} - -impl Snowflake for UserMarker {} - -impl Snowflake for WebhookMarker {} - -mod private { - use super::{ - ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, - CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, - InteractionMarker, MessageMarker, RoleMarker, ScheduledEventEntityMarker, - ScheduledEventMarker, StageMarker, UserMarker, WebhookMarker, - }; - - pub trait Sealed {} - - impl Sealed for ApplicationMarker {} - - impl Sealed for AttachmentMarker {} - - impl Sealed for AuditLogEntryMarker {} - - impl Sealed for ChannelMarker {} - - impl Sealed for CommandMarker {} - - impl Sealed for CommandVersionMarker {} - - impl Sealed for EmojiMarker {} - - impl Sealed for GenericMarker {} - - impl Sealed for GuildMarker {} - - impl Sealed for IntegrationMarker {} - - impl Sealed for InteractionMarker {} - - impl Sealed for MessageMarker {} - - impl Sealed for RoleMarker {} - - impl Sealed for ScheduledEventMarker {} - - impl Sealed for ScheduledEventEntityMarker {} - - impl Sealed for StageMarker {} - - impl Sealed for UserMarker {} - - impl Sealed for WebhookMarker {} -} diff --git a/model/src/id/mod.rs b/model/src/id/mod.rs index d9e9eb0a437..161aede98a3 100644 --- a/model/src/id/mod.rs +++ b/model/src/id/mod.rs @@ -44,7 +44,6 @@ mod r#type; pub use self::r#type::*; -use marker::Snowflake; use serde::{ de::{Deserialize, Deserializer, Error as DeError, Unexpected, Visitor}, ser::{Serialize, Serializer}, @@ -188,65 +187,6 @@ impl Id { } } -impl Id { - /// The Unix epoch of the Snowflake in milliseconds, indicating when it was generated. - /// - /// Derived from bits 22..63 of the id. - /// - /// # Examples - /// - /// ``` - /// use twilight_model::{ - /// datetime::Timestamp, - /// id::{marker::UserMarker, Id}, - /// }; - /// - /// let id = Id::::new(105484726235607040); - /// - /// assert_eq!(id.timestamp(), 1445219918546); - /// - /// assert_eq!( - /// "2015-10-19T01:58:38.546000+00:00", - /// Timestamp::from_micros(id.timestamp() * 1000)? - /// .iso_8601() - /// .to_string() - /// ); - /// # Ok::<(), Box>(()) - /// ``` - #[allow(clippy::cast_possible_wrap)] - pub fn timestamp(self) -> i64 { - // Discord's custom epoch, the unix time in milliseconds for the first second of 2015. - const DISCORD_EPOCH: u64 = 1_420_070_400_000; - - ((self.get() >> 22) + DISCORD_EPOCH) as i64 - } - - /// The id of the internal worker that generated the Snowflake. - /// - /// Derived from bits 17..21 of the id. - #[allow(clippy::cast_possible_truncation)] - pub fn worker_id(self) -> u8 { - ((self.get() & 0x003E_0000) >> 17) as u8 - } - - /// The id of the internal process that generated the Snowflake. - /// - /// Derived from bits 12..16 of the id. - #[allow(clippy::cast_possible_truncation)] - pub fn process_id(self) -> u8 { - ((self.get() & 0x1F000) >> 12) as u8 - } - - /// The increment of the Snowflake. For every id that is generated on a process, this number is - /// incremented. - /// - /// Derived from bits 0..11 of the id. - #[allow(clippy::cast_possible_truncation)] - pub fn increment(self) -> u16 { - (self.get() & 0xFFF) as u16 - } -} - impl Debug for Id { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { f.write_str("Id")?; @@ -457,8 +397,7 @@ mod tests { marker::{ ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, - InteractionMarker, MessageMarker, RoleMarker, Snowflake, StageMarker, UserMarker, - WebhookMarker, + InteractionMarker, MessageMarker, RoleMarker, StageMarker, UserMarker, WebhookMarker, }, Id, IdStringDisplay, }; @@ -474,36 +413,22 @@ mod tests { str::FromStr, }; - assert_impl_all!(ApplicationMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(AttachmentMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!( - AuditLogEntryMarker: Clone, - Copy, - Debug, - Send, - Snowflake, - Sync - ); - assert_impl_all!(ChannelMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(CommandMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!( - CommandVersionMarker: Clone, - Copy, - Debug, - Send, - Snowflake, - Sync - ); - assert_impl_all!(EmojiMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(GenericMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(GuildMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(IntegrationMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(InteractionMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(MessageMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(RoleMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(StageMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(UserMarker: Clone, Copy, Debug, Send, Snowflake, Sync); - assert_impl_all!(WebhookMarker: Clone, Copy, Debug, Send, Snowflake, Sync); + assert_impl_all!(ApplicationMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(AttachmentMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(AuditLogEntryMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(ChannelMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(CommandMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(CommandVersionMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(EmojiMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(GenericMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(GuildMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(IntegrationMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(InteractionMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(MessageMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(RoleMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(StageMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(UserMarker: Clone, Copy, Debug, Send, Sync); + assert_impl_all!(WebhookMarker: Clone, Copy, Debug, Send, Sync); assert_impl_all!(Id: Clone, Copy, Debug, Deserialize<'static>, Display, Eq, From, FromStr, Hash, Ord, PartialEq, PartialEq, PartialEq, PartialOrd, Send, Serialize, Sync, @@ -557,38 +482,6 @@ mod tests { assert_eq!(123_u64, id.cast::()); } - #[test] - fn test_timestamp() { - let expected: i64 = 1_445_219_918_546; - let id = Id::::new(105_484_726_235_607_040); - - assert_eq!(expected, id.timestamp()) - } - - #[test] - fn test_worker_id() { - let expected: u8 = 8; - let id = Id::::new(762_022_344_856_174_632); - - assert_eq!(expected, id.worker_id()) - } - - #[test] - fn test_process_id() { - let expected: u8 = 1; - let id = Id::::new(61_189_081_970_774_016); - - assert_eq!(expected, id.process_id()) - } - - #[test] - fn test_increment() { - let expected: u16 = 40; - let id = Id::::new(762_022_344_856_174_632); - - assert_eq!(expected, id.increment()) - } - /// Test that debugging IDs formats the generic and value as a newtype. #[test] fn test_debug() { diff --git a/util/Cargo.toml b/util/Cargo.toml index 1467ca4e0a8..ffac145bf2d 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -19,14 +19,17 @@ version = "0.8.2" twilight-model = { default-features = false, optional = true, path = "../model" } [dev-dependencies] +chrono = { default-features = false, features = ["std"], version = "0.4" } static_assertions = { default-features = false, version = "1" } +time = { default-features = false, features = ["formatting"], version = "0.3" } [features] default = [] builder = ["twilight-model"] link = ["twilight-model"] permission-calculator = ["twilight-model"] -full = ["builder", "link", "permission-calculator"] +snowflake = ["twilight-model"] +full = ["builder", "link", "permission-calculator", "snowflake"] [package.metadata.docs.rs] all-features = true diff --git a/util/README.md b/util/README.md index 9d88fc7fbdd..0cacb38a85a 100644 --- a/util/README.md +++ b/util/README.md @@ -23,6 +23,11 @@ webhook URLs. Allows the use of a calculator to determine the permissions of a member in a guild or channel. +### `snowflake` + +Allows the use of the `Snowflake` trait, which provides methods for the extraction of +structured information from [Discord snowflakes]. + [`twilight-rs`]: https://github.com/twilight-rs/twilight [codecov badge]: https://img.shields.io/codecov/c/gh/twilight-rs/twilight?logo=codecov&style=for-the-badge&token=E9ERLJL0L2 [codecov link]: https://app.codecov.io/gh/twilight-rs/twilight/ diff --git a/util/src/lib.rs b/util/src/lib.rs index 60fedc847fc..e9fce47f674 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -21,6 +21,11 @@ //! Allows the use of a calculator to determine the permissions of a member in //! a guild or channel. //! +//! ### `snowflake` +//! +//! Allows the use of the `Snowflake` trait, which provides methods for the extraction of +//! structured information from [Discord snowflakes]. +//! //! [`twilight-rs`]: https://github.com/twilight-rs/twilight //! [codecov badge]: https://img.shields.io/codecov/c/gh/twilight-rs/twilight?logo=codecov&style=for-the-badge&token=E9ERLJL0L2 //! [codecov link]: https://app.codecov.io/gh/twilight-rs/twilight/ @@ -56,3 +61,7 @@ pub mod link; #[cfg(feature = "permission-calculator")] pub mod permission_calculator; + +#[cfg(feature = "snowflake")] +#[cfg_attr(docsrs, doc(cfg(feature = "snowflake")))] +pub mod snowflake; diff --git a/util/src/snowflake.rs b/util/src/snowflake.rs new file mode 100644 index 00000000000..3034eaf0f1c --- /dev/null +++ b/util/src/snowflake.rs @@ -0,0 +1,250 @@ +//! Provides the Snowflake trait for defining extractable information from a Discord Snowflake. + +use twilight_model::id::{ + marker::{ + ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, + CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, + InteractionMarker, MessageMarker, RoleMarker, StageMarker, UserMarker, WebhookMarker, + }, + Id, +}; + +/// Snowflake is a trait for defining extractable information from a Snowflake. A Snowflake is a +/// u64 generated by Discord to uniquely identify a resource. +pub trait Snowflake { + /// Returns the u64 backing the Snowflake. + fn id(&self) -> u64; + + /// The Unix epoch of the Snowflake in milliseconds, indicating when it was generated. + /// + /// Derived from bits 22..63 of the id. + /// + /// # Examples + /// + /// See when a user was created using [`chrono`](https://docs.rs/chrono): + /// + /// ``` + /// use chrono::{Utc, TimeZone}; + /// use twilight_util::snowflake::Snowflake; + /// use twilight_model::id::{marker::UserMarker, Id}; + /// + /// let id = Id::::new(105484726235607040).expect("non zero"); + /// + /// assert_eq!( + /// "2015-10-19T01:58:38.546+00:00", + /// Utc.timestamp_millis(id.timestamp()).to_rfc3339() + /// ); + /// ``` + /// + /// See when a user was created using [`time`](https://docs.rs/time): + /// + /// ``` + /// use time::{Duration, format_description::well_known::Rfc3339, OffsetDateTime}; + /// use twilight_util::snowflake::Snowflake; + /// use twilight_model::id::{marker::UserMarker, Id}; + /// + /// # fn main() -> Result<(), Box> { + /// let id = Id::::new(105484726235607040).expect("non zero"); + /// // Convert milliseconds to seconds or nanoseconds. + /// let dur = Duration::milliseconds(id.timestamp()); + /// + /// let ts = OffsetDateTime::from_unix_timestamp(dur.whole_seconds())?; + /// let ts_milli = OffsetDateTime::from_unix_timestamp_nanos(dur.whole_nanoseconds())?; + /// + /// assert_eq!("2015-10-19T01:58:38Z", ts.format(&Rfc3339)?); + /// assert_eq!("2015-10-19T01:58:38.546Z", ts_milli.format(&Rfc3339)?); + /// # Ok(()) } + /// ``` + #[allow(clippy::cast_possible_wrap)] + fn timestamp(&self) -> i64 { + // Discord's custom epoch, the unix time in milliseconds for the first second of 2015. + const DISCORD_EPOCH: u64 = 1_420_070_400_000; + + ((self.id() >> 22) + DISCORD_EPOCH) as i64 + } + + /// The id of the internal worker that generated the Snowflake. + /// + /// Derived from bits 17..21 of the id. + #[allow(clippy::cast_possible_truncation)] + fn worker_id(&self) -> u8 { + ((self.id() & 0x003E_0000) >> 17) as u8 + } + + /// The id of the internal process that generated the Snowflake. + /// + /// Derived from bits 12..16 of the id. + #[allow(clippy::cast_possible_truncation)] + fn process_id(&self) -> u8 { + ((self.id() & 0x1F000) >> 12) as u8 + } + + /// The increment of the Snowflake. For every id that is generated on a process, this number is + /// incremented. + /// + /// Derived from bits 0..11 of the id. + #[allow(clippy::cast_possible_truncation)] + fn increment(&self) -> u16 { + (self.id() & 0xFFF) as u16 + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +#[cfg(test)] +mod tests { + use super::Snowflake; + use static_assertions::{assert_impl_all, assert_obj_safe}; + use twilight_model::id::{ + marker::{ + ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, + CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, + InteractionMarker, MessageMarker, RoleMarker, StageMarker, UserMarker, WebhookMarker, + }, + Id, + }; + + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_obj_safe!(Snowflake); + + #[test] + fn test_timestamp() { + let expected: i64 = 1_445_219_918_546; + let id = Id::::new(105_484_726_235_607_040).expect("non zero"); + + assert_eq!(expected, id.timestamp()) + } + + #[test] + fn test_worker_id() { + let expected: u8 = 8; + let id = Id::::new(762_022_344_856_174_632).expect("non zero"); + + assert_eq!(expected, id.worker_id()) + } + + #[test] + fn test_process_id() { + let expected: u8 = 1; + let id = Id::::new(61_189_081_970_774_016).expect("non zero"); + + assert_eq!(expected, id.process_id()) + } + + #[test] + fn test_increment() { + let expected: u16 = 40; + let id = Id::::new(762_022_344_856_174_632).expect("non zero"); + + assert_eq!(expected, id.increment()) + } +} From efa41c8d3993e33fe3e7cf8cb9cd5e0f5375d56c Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Wed, 19 Jan 2022 19:05:15 -0500 Subject: [PATCH 2/3] remove expects Signed-off-by: Zeyla Hellyer --- util/src/snowflake.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/util/src/snowflake.rs b/util/src/snowflake.rs index 3034eaf0f1c..f355f49166a 100644 --- a/util/src/snowflake.rs +++ b/util/src/snowflake.rs @@ -28,7 +28,7 @@ pub trait Snowflake { /// use twilight_util::snowflake::Snowflake; /// use twilight_model::id::{marker::UserMarker, Id}; /// - /// let id = Id::::new(105484726235607040).expect("non zero"); + /// let id = Id::::new(105484726235607040); /// /// assert_eq!( /// "2015-10-19T01:58:38.546+00:00", @@ -44,7 +44,7 @@ pub trait Snowflake { /// use twilight_model::id::{marker::UserMarker, Id}; /// /// # fn main() -> Result<(), Box> { - /// let id = Id::::new(105484726235607040).expect("non zero"); + /// let id = Id::::new(105484726235607040); /// // Convert milliseconds to seconds or nanoseconds. /// let dur = Duration::milliseconds(id.timestamp()); /// @@ -219,7 +219,7 @@ mod tests { #[test] fn test_timestamp() { let expected: i64 = 1_445_219_918_546; - let id = Id::::new(105_484_726_235_607_040).expect("non zero"); + let id = Id::::new(105_484_726_235_607_040); assert_eq!(expected, id.timestamp()) } @@ -227,7 +227,7 @@ mod tests { #[test] fn test_worker_id() { let expected: u8 = 8; - let id = Id::::new(762_022_344_856_174_632).expect("non zero"); + let id = Id::::new(762_022_344_856_174_632); assert_eq!(expected, id.worker_id()) } @@ -235,7 +235,7 @@ mod tests { #[test] fn test_process_id() { let expected: u8 = 1; - let id = Id::::new(61_189_081_970_774_016).expect("non zero"); + let id = Id::::new(61_189_081_970_774_016); assert_eq!(expected, id.process_id()) } @@ -243,7 +243,7 @@ mod tests { #[test] fn test_increment() { let expected: u16 = 40; - let id = Id::::new(762_022_344_856_174_632).expect("non zero"); + let id = Id::::new(762_022_344_856_174_632); assert_eq!(expected, id.increment()) } From 5da56d624a674b9f565ab9f405c44155d3e65f9b Mon Sep 17 00:00:00 2001 From: Cassandra McCarthy Date: Fri, 21 Jan 2022 13:32:25 -0500 Subject: [PATCH 3/3] address, add note --- model/src/id/marker.rs | 3 ++ util/src/lib.rs | 1 - util/src/snowflake.rs | 63 +++++++++++++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/model/src/id/marker.rs b/model/src/id/marker.rs index 1f21d8adb4a..03c465ce997 100644 --- a/model/src/id/marker.rs +++ b/model/src/id/marker.rs @@ -6,6 +6,9 @@ //! a user's ID is required; by using markers it can be ensured that only an //! ID with a [`RoleMarker`] can be used where a role's ID is required. +// DEVELOPMENT: When adding a new marker, be sure to add its implementation to +// `util/snowflake`. + /// Marker for application IDs. /// /// Types such as [`Message::application_id`] or [`Guild::application_id`] diff --git a/util/src/lib.rs b/util/src/lib.rs index e9fce47f674..4702f42a453 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -63,5 +63,4 @@ pub mod link; pub mod permission_calculator; #[cfg(feature = "snowflake")] -#[cfg_attr(docsrs, doc(cfg(feature = "snowflake")))] pub mod snowflake; diff --git a/util/src/snowflake.rs b/util/src/snowflake.rs index f355f49166a..c556884c57a 100644 --- a/util/src/snowflake.rs +++ b/util/src/snowflake.rs @@ -4,7 +4,9 @@ use twilight_model::id::{ marker::{ ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, - InteractionMarker, MessageMarker, RoleMarker, StageMarker, UserMarker, WebhookMarker, + InteractionMarker, MessageMarker, OauthSkuMarker, OauthTeamMarker, RoleMarker, + ScheduledEventEntityMarker, ScheduledEventMarker, StageMarker, StickerMarker, + StickerPackMarker, StickerPackSkuMarker, UserMarker, WebhookMarker, }, Id, }; @@ -161,18 +163,60 @@ impl Snowflake for Id { } } +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + impl Snowflake for Id { fn id(&self) -> u64 { self.get() } } +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + impl Snowflake for Id { fn id(&self) -> u64 { self.get() } } +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + +impl Snowflake for Id { + fn id(&self) -> u64 { + self.get() + } +} + impl Snowflake for Id { fn id(&self) -> u64 { self.get() @@ -187,16 +231,8 @@ impl Snowflake for Id { #[cfg(test)] mod tests { - use super::Snowflake; + use super::*; use static_assertions::{assert_impl_all, assert_obj_safe}; - use twilight_model::id::{ - marker::{ - ApplicationMarker, AttachmentMarker, AuditLogEntryMarker, ChannelMarker, CommandMarker, - CommandVersionMarker, EmojiMarker, GenericMarker, GuildMarker, IntegrationMarker, - InteractionMarker, MessageMarker, RoleMarker, StageMarker, UserMarker, WebhookMarker, - }, - Id, - }; assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); @@ -210,8 +246,15 @@ mod tests { assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); + assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); assert_impl_all!(Id: Snowflake); assert_obj_safe!(Snowflake);