From c9c512c5a982bcec95abf7e35a4cf0822d1333f3 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sun, 5 Dec 2021 12:53:41 -0500 Subject: [PATCH 01/13] feat(model/id): add 'new_checked' api Add a const method to IDs named `new_checked` that takes a value and creates a non-zero ID, panicking if the value is 0. This is useful when you have a hardcoded value, such as in tests or in const contexts. Code such as: ``` let guild_id = GuildId::new(1).expect("non zero id"); ``` can now become: ``` let guild_id = GuildId::new_checked(1); // or const GUILD_ID: GuildId = GuildId::new_checked(1); ``` Signed-off-by: Zeyla Hellyer --- model/src/id.rs | 410 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 410 insertions(+) diff --git a/model/src/id.rs b/model/src/id.rs index 2b99f71081f..68c3e2c56d4 100644 --- a/model/src/id.rs +++ b/model/src/id.rs @@ -65,6 +65,26 @@ use std::{ pub struct ApplicationId(#[serde(with = "string")] pub NonZeroU64); impl ApplicationId { + /// Create a new non-zero application ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: ApplicationId = ApplicationId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero application ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -115,6 +135,26 @@ impl From for ApplicationId { pub struct AttachmentId(#[serde(with = "string")] pub NonZeroU64); impl AttachmentId { + /// Create a new non-zero attachment ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: AttachmentId = AttachmentId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero attachment ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -165,6 +205,26 @@ impl From for AttachmentId { pub struct AuditLogEntryId(#[serde(with = "string")] pub NonZeroU64); impl AuditLogEntryId { + /// Create a new non-zero audit log entry ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: AuditLogEntryId = AuditLogEntryId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero audit log entry ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -215,6 +275,26 @@ impl From for AuditLogEntryId { pub struct ChannelId(#[serde(with = "string")] pub NonZeroU64); impl ChannelId { + /// Create a new non-zero channel ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: ChannelId = ChannelId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero channel ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -265,6 +345,26 @@ impl From for ChannelId { pub struct CommandId(#[serde(with = "string")] pub NonZeroU64); impl CommandId { + /// Create a new non-zero command ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: CommandId = CommandId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero command ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -315,6 +415,26 @@ impl From for CommandId { pub struct CommandVersionId(#[serde(with = "string")] pub NonZeroU64); impl CommandVersionId { + /// Create a new non-zero command version ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: CommandVersionId = CommandVersionId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero command version ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -365,6 +485,26 @@ impl From for CommandVersionId { pub struct EmojiId(#[serde(with = "string")] pub NonZeroU64); impl EmojiId { + /// Create a new non-zero emoji ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: EmojiId = EmojiId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero emoji ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -415,6 +555,26 @@ impl From for EmojiId { pub struct GenericId(#[serde(with = "string")] pub NonZeroU64); impl GenericId { + /// Create a new non-zero generic ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: GenericId = GenericId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero generic ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -465,6 +625,26 @@ impl From for GenericId { pub struct GuildId(#[serde(with = "string")] pub NonZeroU64); impl GuildId { + /// Create a new non-zero guild ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: GuildId = GuildId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero guild ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -515,6 +695,26 @@ impl From for GuildId { pub struct IntegrationId(#[serde(with = "string")] pub NonZeroU64); impl IntegrationId { + /// Create a new non-zero integration ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: IntegrationId = IntegrationId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero integration ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -565,6 +765,26 @@ impl From for IntegrationId { pub struct InteractionId(#[serde(with = "string")] pub NonZeroU64); impl InteractionId { + /// Create a new non-zero interaction ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: InteractionId = InteractionId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero interaction ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -615,6 +835,26 @@ impl From for InteractionId { pub struct MessageId(#[serde(with = "string")] pub NonZeroU64); impl MessageId { + /// Create a new non-zero message ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: MessageId = MessageId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero message ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -665,6 +905,26 @@ impl From for MessageId { pub struct RoleId(#[serde(with = "string")] pub NonZeroU64); impl RoleId { + /// Create a new non-zero role ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: RoleId = RoleId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero role ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -715,6 +975,26 @@ impl From for RoleId { pub struct StageId(#[serde(with = "string")] pub NonZeroU64); impl StageId { + /// Create a new non-zero stage ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: StageId = StageId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero stage ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -765,6 +1045,26 @@ impl From for StageId { pub struct UserId(#[serde(with = "string")] pub NonZeroU64); impl UserId { + /// Create a new non-zero user ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: UserId = UserId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero user ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -815,6 +1115,26 @@ impl From for UserId { pub struct WebhookId(#[serde(with = "string")] pub NonZeroU64); impl WebhookId { + /// Create a new non-zero webhook ID while checking the value. + /// + /// This is primarily useful in const contexts where you are passing a + /// hardcoded value. + /// + /// # Examples + /// + /// ``` + /// const ID: WebhookId = WebhookId::new_checked(123); + /// + /// println!("id: {}", ID); + /// ``` + /// + /// # Panics + /// + /// Panics if the value is 0. + pub const fn new_checked(n: u64) -> Self { + Self(check(n)) + } + /// Create a non-zero webhook ID without checking the value. /// /// Equivalent to [`NonZeroU64::new_unchecked`]. @@ -859,6 +1179,22 @@ impl From for WebhookId { } } +/// Create a new non-zero u64 while checking the value. +/// +/// This is primarily useful in const contexts where you are passing a +/// hardcoded value. +/// +/// # Panics +/// +/// Panics if the value is 0. +pub const fn check(n: u64) -> NonZeroU64 { + if let Some(non_zero) = NonZeroU64::new(n) { + non_zero + } else { + panic!("id value must not be 0"); + } +} + #[cfg(test)] mod tests { use super::{ @@ -1120,4 +1456,78 @@ mod tests { ], ); } + + #[test] + fn test_new_checked() { + assert_eq!( + 917_105_223_879_766_056, + ApplicationId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + AttachmentId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + AuditLogEntryId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + ChannelId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + CommandId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + CommandVersionId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + EmojiId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + GenericId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + GuildId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + IntegrationId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + InteractionId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + MessageId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + RoleId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + StageId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + UserId::new_checked(917_105_223_879_766_056).get() + ); + assert_eq!( + 917_105_223_879_766_056, + WebhookId::new_checked(917_105_223_879_766_056).get() + ); + } + + #[should_panic] + #[test] + const fn test_new_checked_zero() { + let _ = MessageId::new_checked(0); + } } From dd03c550427bb5a1c21687c5e759487f95ec86ac Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 12:58:15 -0500 Subject: [PATCH 02/13] remove old id reference Signed-off-by: Zeyla Hellyer --- model/src/id/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/model/src/id/mod.rs b/model/src/id/mod.rs index ca42b071621..a4c01f936df 100644 --- a/model/src/id/mod.rs +++ b/model/src/id/mod.rs @@ -95,7 +95,9 @@ impl Id { /// # Examples /// /// ``` - /// const ID: ApplicationId = ApplicationId::new_checked(123); + /// use twilight_model::id::{marker::GenericMarker, Id}; + /// + /// const ID: Id = Id::new_checked(123); /// /// println!("id: {}", ID); /// ``` From d6c2541e2bd439c5dbdbc32300178ce8c63c4f3f Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 14:35:32 -0500 Subject: [PATCH 03/13] bump msrv Signed-off-by: Zeyla Hellyer --- .clippy.toml | 2 +- .github/workflows/check-lib.yml | 2 +- README.md | 4 ++-- cache/in-memory/README.md | 2 +- cache/in-memory/src/lib.rs | 2 +- command-parser/README.md | 2 +- command-parser/src/lib.rs | 2 +- embed-builder/README.md | 2 +- embed-builder/src/lib.rs | 2 +- gateway/README.md | 2 +- gateway/src/lib.rs | 2 +- http/README.md | 2 +- http/src/lib.rs | 2 +- lavalink/README.md | 2 +- lavalink/src/lib.rs | 2 +- mention/README.md | 2 +- mention/src/lib.rs | 2 +- model/README.md | 2 +- model/src/lib.rs | 2 +- standby/README.md | 2 +- standby/src/lib.rs | 2 +- twilight/src/lib.rs | 4 ++-- util/README.md | 2 +- util/src/lib.rs | 2 +- validate/README.md | 4 ++-- validate/src/lib.rs | 2 +- 26 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 349b6909252..5cccb362c14 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.53" +msrv = "1.57" diff --git a/.github/workflows/check-lib.yml b/.github/workflows/check-lib.yml index 4e22788bee7..a473c06595c 100644 --- a/.github/workflows/check-lib.yml +++ b/.github/workflows/check-lib.yml @@ -14,7 +14,7 @@ jobs: name: Minimum supported Rust version runs-on: ubuntu-latest env: - minrust: 1.53 + minrust: 1.57 steps: - name: Checkout sources diff --git a/README.md b/README.md index f0eac03a329..a03817bcd2c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ functionality. Please use the individual crates listed below instead! ## Installation -Twilight supports a MSRV of Rust 1.53+. +Twilight supports a MSRV of Rust 1.57+. We recommend that most users start out with these crates: @@ -230,7 +230,7 @@ All first-party crates are licensed under [ISC][LICENSE.md] [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md [logo]: https://raw.githubusercontent.com/twilight-rs/twilight/main/logo.png -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust [`tracing-log`]: https://github.com/tokio-rs/tracing/tree/master/tracing-log [`twilight-cache-inmemory`]: https://twilight.rs/chapter_1_crates/section_4_cache_inmemory.html [`twilight-embed-builder`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_1_embed_builder.html diff --git a/cache/in-memory/README.md b/cache/in-memory/README.md index d5b4a946c9c..c9bdac53ce3 100644 --- a/cache/in-memory/README.md +++ b/cache/in-memory/README.md @@ -60,6 +60,6 @@ All first-party crates are licensed under [ISC][LICENSE.md] [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/cache/in-memory/src/lib.rs b/cache/in-memory/src/lib.rs index aa4c6af9fea..da0846283f7 100644 --- a/cache/in-memory/src/lib.rs +++ b/cache/in-memory/src/lib.rs @@ -60,7 +60,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![cfg_attr(docsrs, feature(doc_cfg))] #![deny( diff --git a/command-parser/README.md b/command-parser/README.md index b8f8883ce71..7806fc8756a 100644 --- a/command-parser/README.md +++ b/command-parser/README.md @@ -58,7 +58,7 @@ match parser.parse("!echo a message") { [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust [`twilight-gateway`]: https://crates.io/crates/twilight-gateway [`twilight-http`]: https://crates.io/crates/twilight-http [`twilight-rs`]: https://github.com/twilight-rs/twilight diff --git a/command-parser/src/lib.rs b/command-parser/src/lib.rs index ef03ef1707c..7e4d1eb288a 100644 --- a/command-parser/src/lib.rs +++ b/command-parser/src/lib.rs @@ -56,7 +56,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust //! [`twilight-gateway`]: https://crates.io/crates/twilight-gateway //! [`twilight-http`]: https://crates.io/crates/twilight-http //! [`twilight-rs`]: https://github.com/twilight-rs/twilight diff --git a/embed-builder/README.md b/embed-builder/README.md index 3d2085c2800..bc861bd745c 100644 --- a/embed-builder/README.md +++ b/embed-builder/README.md @@ -43,7 +43,7 @@ let embed = EmbedBuilder::new() [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust [the discord docs]: https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds diff --git a/embed-builder/src/lib.rs b/embed-builder/src/lib.rs index a8a669a90d6..55ac71ea44c 100644 --- a/embed-builder/src/lib.rs +++ b/embed-builder/src/lib.rs @@ -45,7 +45,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust //! [the discord docs]: https://discord.com/developers/docs/resources/channel#create-message-using-attachments-within-embeds #![deny( diff --git a/gateway/README.md b/gateway/README.md index 085cc44c7f6..95bf7e9961f 100644 --- a/gateway/README.md +++ b/gateway/README.md @@ -135,6 +135,6 @@ This is disabled by default. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/gateway/src/lib.rs b/gateway/src/lib.rs index c30d0267919..9520d0ed222 100644 --- a/gateway/src/lib.rs +++ b/gateway/src/lib.rs @@ -133,7 +133,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/http/README.md b/http/README.md index 6710dfb3da4..1a1c5b68363 100644 --- a/http/README.md +++ b/http/README.md @@ -113,6 +113,6 @@ async DNS resolver on the application level. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/http/src/lib.rs b/http/src/lib.rs index 2b58aaf04f4..586de1be759 100644 --- a/http/src/lib.rs +++ b/http/src/lib.rs @@ -111,7 +111,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/lavalink/README.md b/lavalink/README.md index d8244ad559e..4d1a5881f02 100644 --- a/lavalink/README.md +++ b/lavalink/README.md @@ -124,6 +124,6 @@ There is also an example of a basic bot located in the [root of the [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md [node]: Node [process]: Lavalink::process -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/lavalink/src/lib.rs b/lavalink/src/lib.rs index 1e8d1e97080..10aba72370c 100644 --- a/lavalink/src/lib.rs +++ b/lavalink/src/lib.rs @@ -122,7 +122,7 @@ //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md //! [node]: Node //! [process]: Lavalink::process -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/mention/README.md b/mention/README.md index 4ce1068d222..af2f1025007 100644 --- a/mention/README.md +++ b/mention/README.md @@ -31,6 +31,6 @@ let message = format!("Hey there, {}!", user_id.mention()); [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/mention/src/lib.rs b/mention/src/lib.rs index 2a511a2f3c3..e202c6e3b94 100644 --- a/mention/src/lib.rs +++ b/mention/src/lib.rs @@ -29,7 +29,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/model/README.md b/model/README.md index 2f623b353f5..a105d19c7f0 100644 --- a/model/README.md +++ b/model/README.md @@ -50,6 +50,6 @@ This is enabled by default. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/model/src/lib.rs b/model/src/lib.rs index 6af5043ebd1..d14595e5806 100644 --- a/model/src/lib.rs +++ b/model/src/lib.rs @@ -48,7 +48,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/standby/README.md b/standby/README.md index 4430106700f..df322909490 100644 --- a/standby/README.md +++ b/standby/README.md @@ -137,6 +137,6 @@ For more examples, check out each of the methods on [`Standby`]. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust diff --git a/standby/src/lib.rs b/standby/src/lib.rs index 3c38a8df9ff..60d2baf6e58 100644 --- a/standby/src/lib.rs +++ b/standby/src/lib.rs @@ -137,7 +137,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, diff --git a/twilight/src/lib.rs b/twilight/src/lib.rs index 27e1f20755f..22e331593b7 100644 --- a/twilight/src/lib.rs +++ b/twilight/src/lib.rs @@ -16,7 +16,7 @@ //! //! ## Installation //! -//! Twilight supports a MSRV of Rust 1.53+. +//! Twilight supports a MSRV of Rust 1.57+. //! //! We recommend that most users start out with these crates: //! @@ -230,7 +230,7 @@ //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md //! [logo]: https://raw.githubusercontent.com/twilight-rs/twilight/main/logo.png -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust //! [`tracing-log`]: https://github.com/tokio-rs/tracing/tree/master/tracing-log //! [`twilight-cache-inmemory`]: https://twilight.rs/chapter_1_crates/section_4_cache_inmemory.html //! [`twilight-embed-builder`]: https://twilight.rs/chapter_1_crates/section_7_first_party/section_1_embed_builder.html diff --git a/util/README.md b/util/README.md index cd71c11c2b0..9d88fc7fbdd 100644 --- a/util/README.md +++ b/util/README.md @@ -32,7 +32,7 @@ a guild or channel. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust [Discord snowflakes]: https://discord.com/developers/docs/reference#snowflakes diff --git a/util/src/lib.rs b/util/src/lib.rs index 145b108f5b4..841cd2a21ee 100644 --- a/util/src/lib.rs +++ b/util/src/lib.rs @@ -30,7 +30,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust //! [Discord snowflakes]: https://discord.com/developers/docs/reference#snowflakes #![deny( diff --git a/validate/README.md b/validate/README.md index eeac28bd4f2..4291797767d 100644 --- a/validate/README.md +++ b/validate/README.md @@ -21,6 +21,6 @@ manually validating any models from [`twilight-model`]. [github link]: https://github.com/twilight-rs/twilight [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -[rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +[rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust - \ No newline at end of file + diff --git a/validate/src/lib.rs b/validate/src/lib.rs index 1159b5e217d..870d33c13bf 100644 --- a/validate/src/lib.rs +++ b/validate/src/lib.rs @@ -19,7 +19,7 @@ //! [github link]: https://github.com/twilight-rs/twilight //! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=for-the-badge&logo=pastebin //! [license link]: https://github.com/twilight-rs/twilight/blob/main/LICENSE.md -//! [rust badge]: https://img.shields.io/badge/rust-1.53+-93450a.svg?style=for-the-badge&logo=rust +//! [rust badge]: https://img.shields.io/badge/rust-1.57+-93450a.svg?style=for-the-badge&logo=rust #![deny( clippy::all, From 952a4a60eb49c807e681811df536f013a27ec9cf Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:10:10 -0500 Subject: [PATCH 04/13] swap new and new_checked Signed-off-by: Zeyla Hellyer --- cache/in-memory/src/event/emoji.rs | 24 ++-- cache/in-memory/src/event/guild.rs | 26 ++-- cache/in-memory/src/event/interaction.rs | 44 +++--- cache/in-memory/src/event/member.rs | 36 ++--- cache/in-memory/src/event/message.rs | 20 +-- cache/in-memory/src/event/reaction.rs | 36 +++-- cache/in-memory/src/event/role.rs | 20 +-- cache/in-memory/src/event/stage_instance.rs | 6 +- cache/in-memory/src/event/voice_state.rs | 78 +++++----- cache/in-memory/src/iter.rs | 12 +- cache/in-memory/src/lib.rs | 30 ++-- cache/in-memory/src/model/emoji.rs | 4 +- cache/in-memory/src/model/member.rs | 6 +- cache/in-memory/src/model/sticker.rs | 16 +-- cache/in-memory/src/permission.rs | 16 +-- cache/in-memory/src/test.rs | 32 ++--- examples/gateway-request-members/src/main.rs | 12 +- examples/http-allowed-mentions/src/main.rs | 4 +- examples/http-get-message/src/main.rs | 2 +- examples/http-proxy/src/main.rs | 2 +- examples/lavalink-basic-bot/src/main.rs | 2 +- gateway/src/shard/impl.rs | 2 +- .../application_command_permissions.rs | 8 +- http/src/client/interaction.rs | 2 +- http/src/client/mod.rs | 86 +++++------ http/src/request/application/command/mod.rs | 8 +- .../command/set_command_permissions.rs | 36 ++--- .../interaction/create_followup_message.rs | 8 +- .../interaction/delete_followup_message.rs | 8 +- .../interaction/delete_original_response.rs | 4 +- .../interaction/get_followup_message.rs | 8 +- .../interaction/get_original_response.rs | 4 +- .../interaction/interaction_callback.rs | 4 +- .../interaction/update_followup_message.rs | 12 +- .../interaction/update_original_response.rs | 6 +- http/src/request/channel/get_channel.rs | 2 +- .../request/channel/invite/create_invite.rs | 10 +- .../request/channel/message/create_message.rs | 2 +- .../channel/message/get_channel_messages.rs | 4 +- .../request/channel/message/update_message.rs | 4 +- .../channel/reaction/create_reaction.rs | 8 +- http/src/request/channel/reaction/mod.rs | 6 +- .../request/channel/thread/update_thread.rs | 2 +- .../channel/update_channel_permission.rs | 4 +- .../update_channel_permission_configured.rs | 4 +- .../request/channel/webhook/create_webhook.rs | 2 +- .../channel/webhook/delete_webhook_message.rs | 6 +- .../channel/webhook/execute_webhook.rs | 6 +- .../webhook/execute_webhook_and_wait.rs | 2 +- .../channel/webhook/update_webhook_message.rs | 10 +- http/src/request/guild/ban/create_ban.rs | 4 +- http/src/request/guild/ban/delete_ban.rs | 4 +- http/src/request/guild/ban/get_bans.rs | 2 +- .../src/request/guild/create_guild/builder.rs | 48 +++---- http/src/request/guild/emoji/get_emoji.rs | 4 +- http/src/request/guild/emoji/get_emojis.rs | 2 +- http/src/request/guild/get_audit_log.rs | 2 +- .../request/guild/get_guild_prune_count.rs | 2 +- .../guild/member/add_role_to_member.rs | 6 +- .../request/guild/member/get_guild_members.rs | 4 +- .../guild/member/search_guild_members.rs | 2 +- .../guild/member/update_guild_member.rs | 4 +- http/src/request/guild/role/create_role.rs | 2 +- .../guild/sticker/create_guild_sticker.rs | 2 +- .../guild/sticker/delete_guild_sticker.rs | 4 +- .../guild/sticker/get_guild_sticker.rs | 4 +- .../guild/sticker/get_guild_stickers.rs | 2 +- .../guild/sticker/update_guild_sticker.rs | 4 +- http/src/request/sticker/get_sticker.rs | 2 +- http/src/request/try_into_request.rs | 4 +- .../request/user/get_current_user_guilds.rs | 4 +- http/src/response/future.rs | 4 +- http/src/response/mod.rs | 26 ++-- http/src/routing/route_display.rs | 12 +- lavalink/src/player.rs | 4 +- mention/README.md | 2 +- mention/benches/fmt.rs | 8 +- mention/src/fmt.rs | 12 +- mention/src/lib.rs | 2 +- mention/src/parse/impl.rs | 20 +-- mention/src/parse/iter.rs | 30 ++-- mention/src/parse/mod.rs | 10 +- model/src/application/command/option.rs | 8 +- model/src/application/command/permissions.rs | 2 +- .../application_command/data/mod.rs | 4 +- .../application_command/data/resolved.rs | 26 ++-- .../interaction/message_component/mod.rs | 16 +-- model/src/application/interaction/mod.rs | 20 +-- model/src/channel/attachment.rs | 2 +- model/src/channel/category_channel.rs | 4 +- model/src/channel/channel_mention.rs | 4 +- model/src/channel/followed_channel.rs | 4 +- model/src/channel/group.rs | 16 +-- .../message/allowed_mentions/builder.rs | 12 +- .../channel/message/allowed_mentions/mod.rs | 4 +- model/src/channel/message/application.rs | 2 +- model/src/channel/message/mention.rs | 4 +- model/src/channel/message/mod.rs | 32 ++--- model/src/channel/message/reference.rs | 8 +- model/src/channel/message/sticker/message.rs | 2 +- model/src/channel/message/sticker/mod.rs | 10 +- model/src/channel/message/sticker/pack.rs | 12 +- model/src/channel/mod.rs | 116 +++++++-------- model/src/channel/permission_overwrite.rs | 8 +- model/src/channel/private_channel.rs | 4 +- model/src/channel/reaction.rs | 22 +-- model/src/channel/reaction_type.rs | 2 +- model/src/channel/stage_instance/mod.rs | 6 +- model/src/channel/text_channel.rs | 12 +- model/src/channel/thread/member.rs | 4 +- model/src/channel/thread/news.rs | 14 +- model/src/channel/thread/private.rs | 14 +- model/src/channel/thread/public.rs | 14 +- model/src/channel/voice_channel.rs | 10 +- model/src/channel/webhook/mod.rs | 22 +-- model/src/gateway/event/gateway.rs | 4 +- .../gateway/payload/incoming/guild_delete.rs | 6 +- .../gateway/payload/incoming/invite_create.rs | 6 +- .../gateway/payload/incoming/member_add.rs | 4 +- .../gateway/payload/incoming/member_chunk.rs | 47 +++--- .../gateway/payload/incoming/member_update.rs | 4 +- model/src/gateway/payload/incoming/ready.rs | 8 +- .../gateway/payload/incoming/role_delete.rs | 4 +- .../gateway/payload/incoming/role_update.rs | 4 +- .../payload/incoming/thread_members_update.rs | 16 +-- .../gateway/payload/incoming/typing_start.rs | 18 +-- .../payload/incoming/unavailable_guild.rs | 2 +- .../payload/incoming/voice_state_update.rs | 22 +-- .../payload/incoming/webhooks_update.rs | 4 +- .../payload/outgoing/request_guild_members.rs | 14 +- model/src/gateway/presence/mod.rs | 10 +- model/src/guild/audit_log/change.rs | 2 +- model/src/guild/audit_log/entry.rs | 6 +- model/src/guild/ban.rs | 2 +- model/src/guild/emoji.rs | 10 +- model/src/guild/info.rs | 2 +- model/src/guild/integration.rs | 14 +- model/src/guild/integration_application.rs | 6 +- model/src/guild/member.rs | 8 +- model/src/guild/mod.rs | 18 +-- model/src/guild/partial_guild.rs | 14 +- model/src/guild/partial_member.rs | 2 +- model/src/guild/preview.rs | 4 +- model/src/guild/role.rs | 10 +- model/src/guild/role_tags.rs | 4 +- model/src/guild/unavailable_guild.rs | 2 +- model/src/guild/widget.rs | 2 +- model/src/id/mod.rs | 134 ++++++++++-------- model/src/invite/channel.rs | 2 +- model/src/invite/guild.rs | 8 +- model/src/invite/mod.rs | 18 +-- model/src/invite/welcome_screen.rs | 6 +- .../src/oauth/current_application_info/mod.rs | 12 +- model/src/oauth/team/member.rs | 4 +- model/src/oauth/team/mod.rs | 4 +- model/src/template/mod.rs | 28 ++-- model/src/user/current_user.rs | 4 +- model/src/user/current_user_guild.rs | 2 +- model/src/user/mod.rs | 4 +- model/src/user/profile.rs | 2 +- model/src/voice/voice_state.rs | 18 +-- standby/README.md | 2 +- standby/src/lib.rs | 128 ++++++++--------- util/src/builder/command.rs | 4 +- util/src/link/webhook.rs | 18 +-- util/src/permission_calculator/mod.rs | 61 ++++---- validate/src/command.rs | 8 +- 167 files changed, 1080 insertions(+), 1044 deletions(-) diff --git a/cache/in-memory/src/event/emoji.rs b/cache/in-memory/src/event/emoji.rs index 881e13058e9..3c7e558d48c 100644 --- a/cache/in-memory/src/event/emoji.rs +++ b/cache/in-memory/src/event/emoji.rs @@ -96,7 +96,7 @@ mod tests { fn user_mod(id: Id) -> Option { if id.get() % 2 == 0 { // Only use user for half - Some(test::user(Id::new(1).expect("non zero"))) + Some(test::user(Id::new_checked(1).expect("non zero"))) } else { None } @@ -105,7 +105,7 @@ mod tests { // Single inserts { let guild_1_emoji_ids = (1..=10) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); let guild_1_emoji = guild_1_emoji_ids .iter() @@ -114,7 +114,7 @@ mod tests { .collect::>(); for emoji in guild_1_emoji { - cache.cache_emoji(Id::new(1).expect("non zero"), emoji); + cache.cache_emoji(Id::new_checked(1).expect("non zero"), emoji); } for id in guild_1_emoji_ids.iter().cloned() { @@ -124,7 +124,7 @@ mod tests { // Ensure the emoji has been added to the per-guild lookup map to prevent // issues like #551 from returning - let guild_emojis = cache.guild_emojis(Id::new(1).expect("non zero")); + let guild_emojis = cache.guild_emojis(Id::new_checked(1).expect("non zero")); assert!(guild_emojis.is_some()); let guild_emojis = guild_emojis.unwrap(); @@ -135,21 +135,21 @@ mod tests { // Bulk inserts { let guild_2_emoji_ids = (11..=20) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); let guild_2_emojis = guild_2_emoji_ids .iter() .copied() .map(|id| test::emoji(id, user_mod(id))) .collect::>(); - cache.cache_emojis(Id::new(2).expect("non zero"), guild_2_emojis); + cache.cache_emojis(Id::new_checked(2).expect("non zero"), guild_2_emojis); for id in guild_2_emoji_ids.iter().cloned() { let global_emoji = cache.emoji(id); assert!(global_emoji.is_some()); } - let guild_emojis = cache.guild_emojis(Id::new(2).expect("non zero")); + let guild_emojis = cache.guild_emojis(Id::new_checked(2).expect("non zero")); assert!(guild_emojis.is_some()); let guild_emojis = guild_emojis.unwrap(); @@ -162,11 +162,11 @@ mod tests { fn test_emoji_removal() { let cache = InMemoryCache::new(); - let guild_id = Id::new(1).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); - let emote = test::emoji(Id::new(1).expect("non zero"), None); - let emote_2 = test::emoji(Id::new(2).expect("non zero"), None); - let emote_3 = test::emoji(Id::new(3).expect("non zero"), None); + let emote = test::emoji(Id::new_checked(1).expect("non zero"), None); + let emote_2 = test::emoji(Id::new_checked(2).expect("non zero"), None); + let emote_3 = test::emoji(Id::new_checked(3).expect("non zero"), None); cache.cache_emoji(guild_id, emote.clone()); cache.cache_emoji(guild_id, emote_2.clone()); @@ -193,7 +193,7 @@ mod tests { assert!(cache.emoji(emote.id).is_some()); assert!(cache.emoji(emote_2.id).is_none()); - let emote_4 = test::emoji(Id::new(4).expect("non zero"), None); + let emote_4 = test::emoji(Id::new_checked(4).expect("non zero"), None); cache.update(&GuildEmojisUpdate { emojis: vec![emote_4.clone()], diff --git a/cache/in-memory/src/event/guild.rs b/cache/in-memory/src/event/guild.rs index 0b04dc6493e..f1e017b18e5 100644 --- a/cache/in-memory/src/event/guild.rs +++ b/cache/in-memory/src/event/guild.rs @@ -234,7 +234,7 @@ mod tests { let timestamp = Timestamp::from_str(DATETIME)?; let channels = Vec::from([GuildChannel::Text(TextChannel { - id: Id::new(111).expect("non zero"), + id: Id::new_checked(111).expect("non zero"), guild_id: None, kind: ChannelType::GuildText, last_message_id: None, @@ -249,7 +249,7 @@ mod tests { })]); let threads = Vec::from([GuildChannel::PublicThread(PublicThread { - id: Id::new(222).expect("non zero"), + id: Id::new_checked(222).expect("non zero"), default_auto_archive_duration: None, guild_id: None, kind: ChannelType::GuildPublicThread, @@ -269,16 +269,16 @@ mod tests { }, member: Some(ThreadMember { flags: 0, - id: Some(Id::new(1).expect("non zero")), + id: Some(Id::new_checked(1).expect("non zero")), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(2).expect("non zero")), + user_id: Some(Id::new_checked(2).expect("non zero")), }), })]); let guild = Guild { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), afk_channel_id: None, afk_timeout: 300, application_id: None, @@ -301,7 +301,7 @@ mod tests { name: "this is a guild".to_owned(), nsfw_level: NSFWLevel::AgeRestricted, owner: Some(false), - owner_id: Id::new(456).expect("non zero"), + owner_id: Id::new_checked(456).expect("non zero"), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-GB".to_owned(), premium_subscription_count: Some(0), @@ -330,11 +330,11 @@ mod tests { cache.cache_guild(guild); let channel = cache - .guild_channel(Id::new(111).expect("non zero")) + .guild_channel(Id::new_checked(111).expect("non zero")) .unwrap(); let thread = cache - .guild_channel(Id::new(222).expect("non zero")) + .guild_channel(Id::new_checked(222).expect("non zero")) .unwrap(); // The channel was given to the cache without a guild ID, but because @@ -343,14 +343,14 @@ mod tests { // correct value. match channel.resource() { GuildChannel::Text(ref c) => { - assert_eq!(Some(Id::new(123).expect("non zero")), c.guild_id); + assert_eq!(Some(Id::new_checked(123).expect("non zero")), c.guild_id); } _ => panic!("{:?}", channel), } match thread.resource() { GuildChannel::PublicThread(ref c) => { - assert_eq!(Some(Id::new(123).expect("non zero")), c.guild_id); + assert_eq!(Some(Id::new_checked(123).expect("non zero")), c.guild_id); } _ => panic!("{:?}", channel), } @@ -376,7 +376,7 @@ mod tests { explicit_content_filter: ExplicitContentFilter::None, features: Vec::new(), icon: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), joined_at: None, large: false, max_members: None, @@ -387,7 +387,7 @@ mod tests { mfa_level: MfaLevel::None, name: "test".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new(1).expect("non zero"), + owner_id: Id::new_checked(1).expect("non zero"), owner: None, permissions: None, preferred_locale: "en_us".to_owned(), @@ -431,7 +431,7 @@ mod tests { mfa_level: guild.mfa_level, name: "test2222".to_owned(), nsfw_level: guild.nsfw_level, - owner_id: Id::new(2).expect("non zero"), + owner_id: Id::new_checked(2).expect("non zero"), owner: guild.owner, permissions: guild.permissions, preferred_locale: guild.preferred_locale, diff --git a/cache/in-memory/src/event/interaction.rs b/cache/in-memory/src/event/interaction.rs index 39ff83293e6..9cc81eb648b 100644 --- a/cache/in-memory/src/event/interaction.rs +++ b/cache/in-memory/src/event/interaction.rs @@ -90,16 +90,16 @@ mod tests { let cache = InMemoryCache::new(); cache.update(&InteractionCreate(Interaction::ApplicationCommand( Box::new(ApplicationCommand { - application_id: Id::new(1).expect("non zero"), - channel_id: Id::new(2).expect("non zero"), + application_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), data: CommandData { - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), name: "command name".into(), options: Vec::new(), resolved: Some(CommandInteractionDataResolved { channels: HashMap::new(), members: IntoIterator::into_iter([( - Id::new(7).expect("non zero"), + Id::new_checked(7).expect("non zero"), InteractionMember { avatar: None, communication_disabled_until: None, @@ -108,12 +108,12 @@ mod tests { pending: false, permissions: Permissions::empty(), premium_since: None, - roles: vec![Id::new(8).expect("non zero")], + roles: vec![Id::new_checked(8).expect("non zero")], }, )]) .collect(), messages: IntoIterator::into_iter([( - Id::new(4).expect("non zero"), + Id::new_checked(4).expect("non zero"), Message { activity: None, application: None, @@ -127,7 +127,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -136,14 +136,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -167,7 +167,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "sticker name".to_owned(), }], referenced_message: None, @@ -179,12 +179,12 @@ mod tests { )]) .collect(), roles: IntoIterator::into_iter([( - Id::new(8).expect("non zero"), + Id::new_checked(8).expect("non zero"), Role { color: 0u32, hoist: false, icon: None, - id: Id::new(8).expect("non zero"), + id: Id::new_checked(8).expect("non zero"), managed: false, mentionable: true, name: "role name".into(), @@ -196,7 +196,7 @@ mod tests { )]) .collect(), users: IntoIterator::into_iter([( - Id::new(7).expect("non zero"), + Id::new_checked(7).expect("non zero"), User { accent_color: None, avatar: Some("different avatar".into()), @@ -205,7 +205,7 @@ mod tests { discriminator: 5678, email: None, flags: None, - id: Id::new(7).expect("non zero"), + id: Id::new_checked(7).expect("non zero"), locale: None, mfa_enabled: None, name: "different name".into(), @@ -218,8 +218,8 @@ mod tests { .collect(), }), }, - guild_id: Some(Id::new(3).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(3).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), kind: InteractionType::ApplicationCommand, member: Some(PartialMember { avatar: None, @@ -239,7 +239,7 @@ mod tests { discriminator: 1234, email: None, flags: None, - id: Id::new(6).expect("non zero"), + id: Id::new_checked(6).expect("non zero"), locale: None, mfa_enabled: None, name: "username".into(), @@ -255,13 +255,13 @@ mod tests { ))); { - let guild_members = cache.guild_members(Id::new(3).expect("non zero")).unwrap(); + let guild_members = cache.guild_members(Id::new_checked(3).expect("non zero")).unwrap(); assert_eq!(guild_members.len(), 2); } { let member = cache - .member(Id::new(3).expect("non zero"), Id::new(6).expect("non zero")) + .member(Id::new_checked(3).expect("non zero"), Id::new_checked(6).expect("non zero")) .unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "avatar string"); @@ -269,14 +269,14 @@ mod tests { { let member = cache - .member(Id::new(3).expect("non zero"), Id::new(7).expect("non zero")) + .member(Id::new_checked(3).expect("non zero"), Id::new_checked(7).expect("non zero")) .unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "different avatar"); } { - let guild_roles = cache.guild_roles(Id::new(3).expect("non zero")).unwrap(); + let guild_roles = cache.guild_roles(Id::new_checked(3).expect("non zero")).unwrap(); assert_eq!(guild_roles.len(), 1); } } diff --git a/cache/in-memory/src/event/member.rs b/cache/in-memory/src/event/member.rs index 0945c5d7af8..37180da0283 100644 --- a/cache/in-memory/src/event/member.rs +++ b/cache/in-memory/src/event/member.rs @@ -219,27 +219,27 @@ mod tests { // Single inserts { let guild_1_user_ids = (1..=10) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); let guild_1_members = guild_1_user_ids .iter() .copied() - .map(|id| test::member(id, Id::new(1).expect("non zero"))) + .map(|id| test::member(id, Id::new_checked(1).expect("non zero"))) .collect::>(); for member in guild_1_members { - cache.cache_member(Id::new(1).expect("non zero"), member); + cache.cache_member(Id::new_checked(1).expect("non zero"), member); } // Check for the cached guild members ids - let cached_roles = cache.guild_members(Id::new(1).expect("non zero")).unwrap(); + let cached_roles = cache.guild_members(Id::new_checked(1).expect("non zero")).unwrap(); assert_eq!(cached_roles.len(), guild_1_user_ids.len()); assert!(guild_1_user_ids.iter().all(|id| cached_roles.contains(id))); // Check for the cached members assert!(guild_1_user_ids .iter() - .all(|id| cache.member(Id::new(1).expect("non zero"), *id).is_some())); + .all(|id| cache.member(Id::new_checked(1).expect("non zero"), *id).is_some())); // Check for the cached users assert!(guild_1_user_ids.iter().all(|id| cache.user(*id).is_some())); @@ -248,17 +248,17 @@ mod tests { // Bulk inserts { let guild_2_user_ids = (1..=10) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); let guild_2_members = guild_2_user_ids .iter() .copied() - .map(|id| test::member(id, Id::new(2).expect("non zero"))) + .map(|id| test::member(id, Id::new_checked(2).expect("non zero"))) .collect::>(); - cache.cache_members(Id::new(2).expect("non zero"), guild_2_members); + cache.cache_members(Id::new_checked(2).expect("non zero"), guild_2_members); // Check for the cached guild members ids - let cached_roles = cache.guild_members(Id::new(1).expect("non zero")).unwrap(); + let cached_roles = cache.guild_members(Id::new_checked(1).expect("non zero")).unwrap(); assert_eq!(cached_roles.len(), guild_2_user_ids.len()); assert!(guild_2_user_ids.iter().all(|id| cached_roles.contains(id))); @@ -266,7 +266,7 @@ mod tests { assert!(guild_2_user_ids .iter() .copied() - .all(|id| cache.member(Id::new(1).expect("non zero"), id).is_some())); + .all(|id| cache.member(Id::new_checked(1).expect("non zero"), id).is_some())); // Check for the cached users assert!(guild_2_user_ids.iter().all(|id| cache.user(*id).is_some())); @@ -275,49 +275,49 @@ mod tests { #[test] fn test_cache_user_guild_state() { - let user_id = Id::new(2).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let cache = InMemoryCache::new(); cache.cache_user( Cow::Owned(test::user(user_id)), - Some(Id::new(1).expect("non zero")), + Some(Id::new_checked(1).expect("non zero")), ); // Test the guild's ID is the only one in the user's set of guilds. { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(user_guilds.contains(&Id::new(1).expect("non zero"))); + assert!(user_guilds.contains(&Id::new_checked(1).expect("non zero"))); assert_eq!(1, user_guilds.len()); } // Test that a second guild will cause 2 in the set. cache.cache_user( Cow::Owned(test::user(user_id)), - Some(Id::new(3).expect("non zero")), + Some(Id::new_checked(3).expect("non zero")), ); { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(user_guilds.contains(&Id::new(3).expect("non zero"))); + assert!(user_guilds.contains(&Id::new_checked(3).expect("non zero"))); assert_eq!(2, user_guilds.len()); } // Test that removing a user from a guild will cause the ID to be // removed from the set, leaving the other ID. cache.update(&MemberRemove { - guild_id: Id::new(3).expect("non zero"), + guild_id: Id::new_checked(3).expect("non zero"), user: test::user(user_id), }); { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(!user_guilds.contains(&Id::new(3).expect("non zero"))); + assert!(!user_guilds.contains(&Id::new_checked(3).expect("non zero"))); assert_eq!(1, user_guilds.len()); } // Test that removing the user from its last guild removes the user's // entry. cache.update(&MemberRemove { - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), user: test::user(user_id), }); assert!(!cache.users.contains_key(&user_id)); diff --git a/cache/in-memory/src/event/message.rs b/cache/in-memory/src/event/message.rs index 945f03f50e1..c5939a0d3fb 100644 --- a/cache/in-memory/src/event/message.rs +++ b/cache/in-memory/src/event/message.rs @@ -159,7 +159,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -168,14 +168,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -206,33 +206,33 @@ mod tests { }; cache.update(&MessageCreate(msg.clone())); - msg.id = Id::new(5).expect("non zero"); + msg.id = Id::new_checked(5).expect("non zero"); cache.update(&MessageCreate(msg)); { let entry = cache .user_guilds - .get(&Id::new(3).expect("non zero")) + .get(&Id::new_checked(3).expect("non zero")) .unwrap(); assert_eq!(entry.value().len(), 1); } assert_eq!( cache - .member(Id::new(1).expect("non zero"), Id::new(3).expect("non zero")) + .member(Id::new_checked(1).expect("non zero"), Id::new_checked(3).expect("non zero")) .unwrap() .user_id, - Id::new(3).expect("non zero"), + Id::new_checked(3).expect("non zero"), ); { let entry = cache .channel_messages - .get(&Id::new(2).expect("non zero")) + .get(&Id::new_checked(2).expect("non zero")) .unwrap(); assert_eq!(entry.value().len(), 2); } let mut iter = cache - .channel_messages(Id::new(2).expect("non zero")) + .channel_messages(Id::new_checked(2).expect("non zero")) .expect("channel is in cache"); // messages are iterated over in descending order from insertion diff --git a/cache/in-memory/src/event/reaction.rs b/cache/in-memory/src/event/reaction.rs index 45fc5ad517e..400d245b53a 100644 --- a/cache/in-memory/src/event/reaction.rs +++ b/cache/in-memory/src/event/reaction.rs @@ -125,7 +125,9 @@ mod tests { #[test] fn test_reaction_add() { let cache = test::cache_with_message_and_reactions(); - let msg = cache.message(Id::new(4).expect("non zero")).unwrap(); + let msg = cache + .message(Id::new_checked(4).expect("non zero")) + .unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -148,17 +150,19 @@ mod tests { fn test_reaction_remove() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemove(Reaction { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: None, - message_id: Id::new(4).expect("non zero"), - user_id: Id::new(5).expect("non zero"), + message_id: Id::new_checked(4).expect("non zero"), + user_id: Id::new_checked(5).expect("non zero"), })); - let msg = cache.message(Id::new(4).expect("non zero")).unwrap(); + let msg = cache + .message(Id::new_checked(4).expect("non zero")) + .unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -181,12 +185,14 @@ mod tests { fn test_reaction_remove_all() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemoveAll { - channel_id: Id::new(2).expect("non zero"), - message_id: Id::new(4).expect("non zero"), - guild_id: Some(Id::new(1).expect("non zero")), + channel_id: Id::new_checked(2).expect("non zero"), + message_id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), }); - let msg = cache.message(Id::new(4).expect("non zero")).unwrap(); + let msg = cache + .message(Id::new_checked(4).expect("non zero")) + .unwrap(); assert_eq!(msg.reactions.len(), 0); } @@ -195,15 +201,17 @@ mod tests { fn test_reaction_remove_emoji() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemoveEmoji { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Id::new(1).expect("non zero"), - message_id: Id::new(4).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + message_id: Id::new_checked(4).expect("non zero"), }); - let msg = cache.message(Id::new(4).expect("non zero")).unwrap(); + let msg = cache + .message(Id::new_checked(4).expect("non zero")) + .unwrap(); assert_eq!(msg.reactions.len(), 1); diff --git a/cache/in-memory/src/event/role.rs b/cache/in-memory/src/event/role.rs index 46769a8defb..b72ffd27428 100644 --- a/cache/in-memory/src/event/role.rs +++ b/cache/in-memory/src/event/role.rs @@ -79,8 +79,8 @@ mod tests { let cache = InMemoryCache::new(); cache.update(&RoleCreate { - guild_id: Id::new(1).expect("non zero"), - role: test::role(Id::new(2).expect("non zero")), + guild_id: Id::new_checked(1).expect("non zero"), + role: test::role(Id::new_checked(2).expect("non zero")), }); { @@ -88,7 +88,7 @@ mod tests { 1, cache .guild_roles - .get(&Id::new(1).expect("non zero")) + .get(&Id::new_checked(1).expect("non zero")) .unwrap() .len() ); @@ -96,7 +96,7 @@ mod tests { assert_eq!( "test".to_string(), - cache.role(Id::new(2).expect("non zero")).unwrap().name + cache.role(Id::new_checked(2).expect("non zero")).unwrap().name ); } } @@ -109,7 +109,7 @@ mod tests { { // The role ids for the guild with id 1 let guild_1_role_ids = (1..=10) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); // Map the role ids to a test role let guild_1_roles = guild_1_role_ids @@ -119,11 +119,11 @@ mod tests { .collect::>(); // Cache all the roles using cache role for role in guild_1_roles.clone() { - cache.cache_role(Id::new(1).expect("non zero"), role); + cache.cache_role(Id::new_checked(1).expect("non zero"), role); } // Check for the cached guild role ids - let cached_roles = cache.guild_roles(Id::new(1).expect("non zero")).unwrap(); + let cached_roles = cache.guild_roles(Id::new_checked(1).expect("non zero")).unwrap(); assert_eq!(cached_roles.len(), guild_1_role_ids.len()); assert!(guild_1_role_ids.iter().all(|id| cached_roles.contains(id))); @@ -139,7 +139,7 @@ mod tests { { // The role ids for the guild with id 2 let guild_2_role_ids = (101..=110) - .map(|n| Id::new(n).expect("non zero")) + .map(|n| Id::new_checked(n).expect("non zero")) .collect::>(); // Map the role ids to a test role let guild_2_roles = guild_2_role_ids @@ -148,10 +148,10 @@ mod tests { .map(test::role) .collect::>(); // Cache all the roles using cache roles - cache.cache_roles(Id::new(2).expect("non zero"), guild_2_roles.clone()); + cache.cache_roles(Id::new_checked(2).expect("non zero"), guild_2_roles.clone()); // Check for the cached guild role ids - let cached_roles = cache.guild_roles(Id::new(2).expect("non zero")).unwrap(); + let cached_roles = cache.guild_roles(Id::new_checked(2).expect("non zero")).unwrap(); assert_eq!(cached_roles.len(), guild_2_role_ids.len()); assert!(guild_2_role_ids.iter().all(|id| cached_roles.contains(id))); diff --git a/cache/in-memory/src/event/stage_instance.rs b/cache/in-memory/src/event/stage_instance.rs index 176cf2a602d..d00ab62f186 100644 --- a/cache/in-memory/src/event/stage_instance.rs +++ b/cache/in-memory/src/event/stage_instance.rs @@ -84,10 +84,10 @@ mod tests { let cache = InMemoryCache::new(); let stage_instance = StageInstance { - channel_id: Id::new(1).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), discoverable_disabled: true, - guild_id: Id::new(2).expect("non zero"), - id: Id::new(3).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), privacy_level: PrivacyLevel::GuildOnly, topic: "topic".into(), }; diff --git a/cache/in-memory/src/event/voice_state.rs b/cache/in-memory/src/event/voice_state.rs index 36c4854f0a7..3ff2810bee9 100644 --- a/cache/in-memory/src/event/voice_state.rs +++ b/cache/in-memory/src/event/voice_state.rs @@ -113,9 +113,9 @@ mod tests { { // Ids for this insert let (guild_id, channel_id, user_id) = ( - Id::new(1).expect("non zero"), - Id::new(11).expect("non zero"), - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(11).expect("non zero"), + Id::new_checked(1).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); @@ -137,9 +137,9 @@ mod tests { { // Ids for this insert let (guild_id, channel_id, user_id) = ( - Id::new(2).expect("non zero"), - Id::new(21).expect("non zero"), - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), + Id::new_checked(21).expect("non zero"), + Id::new_checked(2).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); @@ -161,9 +161,9 @@ mod tests { { // Ids for this insert let (guild_id, channel_id, user_id) = ( - Id::new(1).expect("non zero"), - Id::new(12).expect("non zero"), - Id::new(3).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(12).expect("non zero"), + Id::new_checked(3).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); @@ -186,9 +186,9 @@ mod tests { { // Ids for this insert let (guild_id, channel_id, user_id) = ( - Id::new(1).expect("non zero"), - Id::new(11).expect("non zero"), - Id::new(3).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(11).expect("non zero"), + Id::new_checked(3).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); @@ -210,9 +210,9 @@ mod tests { // User 3 dcs (2 channels, 2 guilds) { let (guild_id, channel_id, user_id) = ( - Id::new(1).expect("non zero"), - Id::new(11).expect("non zero"), - Id::new(3).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(11).expect("non zero"), + Id::new_checked(3).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); @@ -230,9 +230,9 @@ mod tests { // User 2 dcs (1 channel, 1 guild) { let (guild_id, channel_id, user_id) = ( - Id::new(2).expect("non zero"), - Id::new(21).expect("non zero"), - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), + Id::new_checked(21).expect("non zero"), + Id::new_checked(2).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); @@ -252,9 +252,9 @@ mod tests { // User 1 dcs (0 channels, 0 guilds) { let (guild_id, _channel_id, user_id) = ( - Id::new(1).expect("non zero"), - Id::::new(11).expect("non zero"), - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::::new_checked(11).expect("non zero"), + Id::new_checked(1).expect("non zero"), ); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); @@ -269,28 +269,28 @@ mod tests { fn test_voice_states() { let cache = InMemoryCache::new(); cache.cache_voice_state(test::voice_state( - Id::new(1).expect("non zero"), - Some(Id::new(2).expect("non zero")), - Id::new(3).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Some(Id::new_checked(2).expect("non zero")), + Id::new_checked(3).expect("non zero"), )); cache.cache_voice_state(test::voice_state( - Id::new(1).expect("non zero"), - Some(Id::new(2).expect("non zero")), - Id::new(4).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Some(Id::new_checked(2).expect("non zero")), + Id::new_checked(4).expect("non zero"), )); // Returns both voice states for the channel that exists. assert_eq!( 2, cache - .voice_channel_states(Id::new(2).expect("non zero")) + .voice_channel_states(Id::new_checked(2).expect("non zero")) .unwrap() .count() ); // Returns None if the channel does not exist. assert!(cache - .voice_channel_states(Id::new(1).expect("non zero")) + .voice_channel_states(Id::new_checked(1).expect("non zero")) .is_none()); } @@ -303,7 +303,7 @@ mod tests { cache.update(&VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: None, mute: false, self_deaf: false, @@ -312,7 +312,7 @@ mod tests { session_id: "38fj3jfkh3pfho3prh2".to_string(), suppress: false, token: None, - user_id: Id::new(1).expect("non zero"), + user_id: Id::new_checked(1).expect("non zero"), request_to_speak_timestamp: Some( Timestamp::from_str("2021-04-21T22:16:50+00:00").expect("proper datetime"), ), @@ -327,14 +327,14 @@ mod tests { let cache = InMemoryCache::new(); let mutation = VoiceStateUpdate(VoiceState { - channel_id: Some(Id::new(4).expect("non zero")), + channel_id: Some(Id::new_checked(4).expect("non zero")), deaf: false, - guild_id: Some(Id::new(2).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), joined_at, mute: false, nick: None, @@ -349,7 +349,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -366,7 +366,7 @@ mod tests { session_id: "".to_owned(), suppress: false, token: None, - user_id: Id::new(3).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), request_to_speak_timestamp: Some( Timestamp::from_str("2021-04-21T22:16:50+00:00").expect("proper datetime"), ), @@ -378,16 +378,16 @@ mod tests { { let entry = cache .user_guilds - .get(&Id::new(3).expect("non zero")) + .get(&Id::new_checked(3).expect("non zero")) .unwrap(); assert_eq!(entry.value().len(), 1); } assert_eq!( cache - .member(Id::new(2).expect("non zero"), Id::new(3).expect("non zero")) + .member(Id::new_checked(2).expect("non zero"), Id::new_checked(3).expect("non zero")) .unwrap() .user_id, - Id::new(3).expect("non zero"), + Id::new_checked(3).expect("non zero"), ); } } diff --git a/cache/in-memory/src/iter.rs b/cache/in-memory/src/iter.rs index f7d112f6298..42d3aca1be0 100644 --- a/cache/in-memory/src/iter.rs +++ b/cache/in-memory/src/iter.rs @@ -115,7 +115,7 @@ impl Deref for IterReference<'_, K, V> { /// let cache = InMemoryCache::new(); /// /// // later in the application... -/// let guild_id = Id::new(1).expect("non zero id"); +/// let guild_id = Id::new_checked(1).expect("non zero id"); /// let maybe_guild_members = cache.guild_members(guild_id); /// /// if let Some(guild_members) = maybe_guild_members { @@ -279,7 +279,7 @@ impl<'a, K: Eq + Hash, V> Iterator for ResourceIter<'a, K, V> { /// use twilight_cache_inmemory::InMemoryCache; /// use twilight_model::id::{ChannelId, MessageId}; /// -/// let channel_id = ChannelId::new(1).expect("non zero id"); +/// let channel_id = ChannelId::new_checked(1).expect("non zero id"); /// /// let cache = InMemoryCache::new(); /// let message_ids = cache.channel_messages(channel_id)?; @@ -349,11 +349,11 @@ mod tests { #[test] fn test_iter() { - let guild_id = Id::new(1).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); let users = &[ - (Id::new(2).expect("non zero"), Some(guild_id)), - (Id::new(3).expect("non zero"), Some(guild_id)), - (Id::new(4).expect("non zero"), None), + (Id::new_checked(2).expect("non zero"), Some(guild_id)), + (Id::new_checked(3).expect("non zero"), Some(guild_id)), + (Id::new_checked(4).expect("non zero"), None), ]; let cache = InMemoryCache::new(); diff --git a/cache/in-memory/src/lib.rs b/cache/in-memory/src/lib.rs index da0846283f7..be34918f2be 100644 --- a/cache/in-memory/src/lib.rs +++ b/cache/in-memory/src/lib.rs @@ -418,8 +418,8 @@ impl InMemoryCache { /// .resource_types(resource_types) /// .build(); /// - /// let channel_id = Id::new(4).expect("non zero"); - /// let user_id = Id::new(5).expect("non zero"); + /// let channel_id = Id::new_checked(4).expect("non zero"); + /// let user_id = Id::new_checked(5).expect("non zero"); /// /// let permissions = cache.permissions().in_channel(user_id, channel_id)?; /// println!("member has these permissions: {:?}", permissions); @@ -936,8 +936,8 @@ mod tests { fn test_syntax_update() { let cache = InMemoryCache::new(); cache.update(&RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(1).expect("non zero"), }); } @@ -945,12 +945,12 @@ mod tests { fn test_clear() { let cache = InMemoryCache::new(); cache.cache_emoji( - Id::new(1).expect("non zero"), - test::emoji(Id::new(3).expect("non zero"), None), + Id::new_checked(1).expect("non zero"), + test::emoji(Id::new_checked(3).expect("non zero"), None), ); cache.cache_member( - Id::new(2).expect("non zero"), - test::member(Id::new(4).expect("non zero"), Id::new(2).expect("non zero")), + Id::new_checked(2).expect("non zero"), + test::member(Id::new_checked(4).expect("non zero"), Id::new_checked(2).expect("non zero")), ); cache.clear(); assert!(cache.emojis.is_empty()); @@ -961,8 +961,8 @@ mod tests { fn test_highest_role() { let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero"); let cache = InMemoryCache::new(); - let guild_id = Id::new(1).expect("non zero"); - let user = test::user(Id::new(1).expect("non zero")); + let guild_id = Id::new_checked(1).expect("non zero"); + let user = test::user(Id::new_checked(1).expect("non zero")); cache.cache_member( guild_id, Member { @@ -975,7 +975,7 @@ mod tests { nick: None, pending: false, premium_since: None, - roles: vec![Id::new(1).expect("non zero"), Id::new(2).expect("non zero")], + roles: vec![Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")], user, }, ); @@ -987,7 +987,7 @@ mod tests { color: 0, hoist: false, icon: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), managed: false, mentionable: false, name: "test".to_owned(), @@ -1000,7 +1000,7 @@ mod tests { color: 0, hoist: false, icon: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), managed: false, mentionable: false, name: "test".to_owned(), @@ -1013,8 +1013,8 @@ mod tests { ); assert_eq!( - cache.member_highest_role(guild_id, Id::new(1).expect("non zero")), - Some(Id::new(2).expect("non zero")) + cache.member_highest_role(guild_id, Id::new_checked(1).expect("non zero")), + Some(Id::new_checked(2).expect("non zero")) ); } } diff --git a/cache/in-memory/src/model/emoji.rs b/cache/in-memory/src/model/emoji.rs index 780d0991584..be29ff0ad79 100644 --- a/cache/in-memory/src/model/emoji.rs +++ b/cache/in-memory/src/model/emoji.rs @@ -100,7 +100,7 @@ mod tests { #[test] fn test_eq_emoji() { let emoji = Emoji { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), animated: true, name: "foo".to_owned(), managed: false, @@ -110,7 +110,7 @@ mod tests { available: true, }; let cached = CachedEmoji { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), animated: true, name: "foo".to_owned(), managed: false, diff --git a/cache/in-memory/src/model/member.rs b/cache/in-memory/src/model/member.rs index 2e25bd8938d..af01c3f090d 100644 --- a/cache/in-memory/src/model/member.rs +++ b/cache/in-memory/src/model/member.rs @@ -185,7 +185,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: Some(false), - guild_id: Id::new(3).expect("non zero"), + guild_id: Id::new_checked(3).expect("non zero"), joined_at, mute: Some(true), nick: Some("member nick".to_owned()), @@ -205,7 +205,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: None, mfa_enabled: None, name: "bar".to_owned(), @@ -224,7 +224,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(3).expect("non zero"), + guild_id: Id::new_checked(3).expect("non zero"), joined_at, mute: true, nick: Some("member nick".to_owned()), diff --git a/cache/in-memory/src/model/sticker.rs b/cache/in-memory/src/model/sticker.rs index 2df008c3811..fc577dc76c4 100644 --- a/cache/in-memory/src/model/sticker.rs +++ b/cache/in-memory/src/model/sticker.rs @@ -147,11 +147,11 @@ mod tests { available: true, description: Some("sticker".into()), format_type: StickerFormatType::Png, - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(2).expect("non zero"), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new(3).expect("non zero")), + pack_id: Some(Id::new_checked(3).expect("non zero")), sort_value: Some(1), tags: "foo,bar,baz".into(), user: Some(User { @@ -162,7 +162,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), @@ -179,14 +179,14 @@ mod tests { available: true, description: "sticker".into(), format_type: StickerFormatType::Png, - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(2).expect("non zero"), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new(3).expect("non zero")), + pack_id: Some(Id::new_checked(3).expect("non zero")), sort_value: Some(1), tags: "foo,bar,baz".into(), - user_id: Some(Id::new(1).expect("non zero")), + user_id: Some(Id::new_checked(1).expect("non zero")), }; assert_eq!(cached, sticker); diff --git a/cache/in-memory/src/permission.rs b/cache/in-memory/src/permission.rs index 224933be417..9dd07047c65 100644 --- a/cache/in-memory/src/permission.rs +++ b/cache/in-memory/src/permission.rs @@ -280,8 +280,8 @@ impl<'a> InMemoryCachePermissions<'a> { /// /// // later on... /// - /// let channel_id = Id::new(4).expect("non zero"); - /// let user_id = Id::new(5).expect("non zero"); + /// let channel_id = Id::new_checked(4).expect("non zero"); + /// let user_id = Id::new_checked(5).expect("non zero"); /// /// let permissions = cache.permissions().in_channel(user_id, channel_id)?; /// println!( @@ -367,8 +367,8 @@ impl<'a> InMemoryCachePermissions<'a> { /// /// // later on... /// - /// let guild_id = Id::new(4).expect("non zero"); - /// let user_id = Id::new(5).expect("non zero"); + /// let guild_id = Id::new_checked(4).expect("non zero"); + /// let user_id = Id::new_checked(5).expect("non zero"); /// /// let permissions = cache.permissions().root(user_id, guild_id)?; /// println!( @@ -539,7 +539,7 @@ mod tests { /// Guild ID used in tests. fn guild_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } /// ID of the `@everyone` role. @@ -549,17 +549,17 @@ mod tests { /// User ID used in tests. fn user_id() -> Id { - Id::new(2).expect("non zero") + Id::new_checked(2).expect("non zero") } /// ID of another role. fn other_role_id() -> Id { - Id::new(3).expect("non zero") + Id::new_checked(3).expect("non zero") } /// ID of the user that owns the guild with the ID [`GUILD_ID`]. fn owner_id() -> Id { - Id::new(4).expect("non zero") + Id::new_checked(4).expect("non zero") } /// ID of the #general channel in the guild. diff --git a/cache/in-memory/src/test.rs b/cache/in-memory/src/test.rs index d1d18f6afaa..46b9d23410e 100644 --- a/cache/in-memory/src/test.rs +++ b/cache/in-memory/src/test.rs @@ -32,7 +32,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -41,14 +41,14 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -81,16 +81,16 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { cache.update(&MessageCreate(msg)); let mut reaction = ReactionAdd(Reaction { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("member nick".to_owned()), @@ -105,7 +105,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -115,8 +115,8 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { verified: None, }, }), - message_id: Id::new(4).expect("non zero"), - user_id: Id::new(3).expect("non zero"), + message_id: Id::new_checked(4).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), }); cache.update(&reaction); @@ -125,7 +125,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: None, @@ -140,7 +140,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 2, email: None, flags: None, - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -150,7 +150,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { verified: None, }, }); - reaction.user_id = Id::new(5).expect("non zero"); + reaction.user_id = Id::new_checked(5).expect("non zero"); cache.update(&reaction); @@ -171,7 +171,7 @@ pub fn current_user(id: u64) -> CurrentUser { bot: true, discriminator: 9876, email: None, - id: Id::new(id).expect("non zero"), + id: Id::new_checked(id).expect("non zero"), mfa_enabled: true, name: "test".to_owned(), verified: Some(true), @@ -196,8 +196,8 @@ pub fn emoji(id: Id, user: Option) -> Emoji { } pub fn guild_channel_text() -> (Id, Id, GuildChannel) { - let guild_id = Id::new(1).expect("non zero"); - let channel_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let channel_id = Id::new_checked(2).expect("non zero"); let channel = GuildChannel::Text(TextChannel { guild_id: Some(guild_id), id: channel_id, diff --git a/examples/gateway-request-members/src/main.rs b/examples/gateway-request-members/src/main.rs index c36362dd299..0e2560ec1d7 100644 --- a/examples/gateway-request-members/src/main.rs +++ b/examples/gateway-request-members/src/main.rs @@ -30,20 +30,20 @@ async fn main() -> Result<(), Box> { // Additionally, you can pass in a "nonce" and get it back in // the received member chunk. This can be used to help identify // which request the member is from. - let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) .nonce("requesting a single member") - .user_id(Id::new(2).expect("non zero")); + .user_id(Id::new_checked(2).expect("non zero")); shard.command(&request).await?; // Similarly, you can also request multiple members. Only 100 // members by ID can be requested at a time, so the builder will // check to make sure you're requesting at most that many: - let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) .nonce("requesting two member") .user_ids(vec![ - Id::new(2).expect("non zero"), - Id::new(3).expect("non zero"), + Id::new_checked(2).expect("non zero"), + Id::new_checked(3).expect("non zero"), ]) .unwrap(); @@ -55,7 +55,7 @@ async fn main() -> Result<(), Box> { // number of members to retrieve can be specified. Here we'll // request a list of up to 50 members and their current presence // details whose names start with the letters "tw": - let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) .nonce("querying for members") .presences(true) .query("tw", Some(50)); diff --git a/examples/http-allowed-mentions/src/main.rs b/examples/http-allowed-mentions/src/main.rs index 73c073ffddb..38c6e3ab8ca 100644 --- a/examples/http-allowed-mentions/src/main.rs +++ b/examples/http-allowed-mentions/src/main.rs @@ -16,8 +16,8 @@ async fn main() -> Result<(), Box> { //add an empty allowed mentions, this will prevent any and all pings .default_allowed_mentions(AllowedMentions::default()) .build(); - let channel_id = Id::new(381_926_291_785_383_946).expect("non zero"); - let user_id = Id::new(77_469_400_222_932_992).expect("non zero"); + let channel_id = Id::new_checked(381_926_291_785_383_946).expect("non zero"); + let user_id = Id::new_checked(77_469_400_222_932_992).expect("non zero"); //here we want to warn a user about trying to ping everyone so we override to allow pinging them //but since we did not allow @everyone pings it will not ping everyone diff --git a/examples/http-get-message/src/main.rs b/examples/http-get-message/src/main.rs index 72e5dd2f580..ecaea470e2c 100644 --- a/examples/http-get-message/src/main.rs +++ b/examples/http-get-message/src/main.rs @@ -9,7 +9,7 @@ async fn main() -> Result<(), Box> { tracing_subscriber::fmt::init(); let client = Client::new(env::var("DISCORD_TOKEN")?); - let channel_id = Id::new(381_926_291_785_383_946).expect("non zero"); + let channel_id = Id::new_checked(381_926_291_785_383_946).expect("non zero"); future::join_all((1u8..=10).map(|x| { client diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index 2cbf88d9eb3..842f33e0b8e 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -12,7 +12,7 @@ async fn main() -> Result<(), Box> { .proxy("localhost:3000".to_owned(), true) .ratelimiter(None) .build(); - let channel_id = Id::new(620_980_184_606_048_278).expect("non zero"); + let channel_id = Id::new_checked(620_980_184_606_048_278).expect("non zero"); future::join_all((1u8..=10).map(|x| { client diff --git a/examples/lavalink-basic-bot/src/main.rs b/examples/lavalink-basic-bot/src/main.rs index 2faaa85773d..e99884ef615 100644 --- a/examples/lavalink-basic-bot/src/main.rs +++ b/examples/lavalink-basic-bot/src/main.rs @@ -113,7 +113,7 @@ async fn join(msg: Message, state: State) -> Result<(), Box()?).expect("non zero"); + let channel_id = Id::new_checked(msg.content.parse::()?).expect("non zero"); let guild_id = msg.guild_id.expect("known to be present"); state diff --git a/gateway/src/shard/impl.rs b/gateway/src/shard/impl.rs index b0e1193946d..9b659ec62e9 100644 --- a/gateway/src/shard/impl.rs +++ b/gateway/src/shard/impl.rs @@ -590,7 +590,7 @@ impl Shard { /// // Query members whose names start with "tw" and limit the results to /// // 10 members. /// let request = - /// RequestGuildMembers::builder(Id::new(1).expect("non zero")) + /// RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) /// .query("tw", Some(10)); /// /// // Send the request over the shard. diff --git a/http/benches/application_command_permissions.rs b/http/benches/application_command_permissions.rs index 9fa67b91e68..0aa92ced560 100644 --- a/http/benches/application_command_permissions.rs +++ b/http/benches/application_command_permissions.rs @@ -10,9 +10,9 @@ fn commands(commands: usize, permissions: usize) -> Vec<(Id, Comm .map(|id| { (0..permissions).map(move |_| { ( - Id::new(id as u64).expect("non zero"), + Id::new_checked(id as u64).expect("non zero"), CommandPermissions { - id: CommandPermissionsType::Role(Id::new(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), permission: true, }, ) @@ -24,7 +24,7 @@ fn commands(commands: usize, permissions: usize) -> Vec<(Id, Comm fn criterion_benchmark(c: &mut Criterion) { let client = Client::new(String::new()); - let application_id = Id::new(1).expect("non zero"); + let application_id = Id::new_checked(1).expect("non zero"); let command_counts = [5usize, 10, 50, 100]; let permission_counts = [2usize, 5, 10]; @@ -39,7 +39,7 @@ fn criterion_benchmark(c: &mut Criterion) { b.iter(|| { assert!(client .interaction(application_id) - .set_command_permissions(Id::new(2).expect("non zero"), &list) + .set_command_permissions(Id::new_checked(2).expect("non zero"), &list) .is_ok()); }); }); diff --git a/http/src/client/interaction.rs b/http/src/client/interaction.rs index cacc867123b..a5b069daf83 100644 --- a/http/src/client/interaction.rs +++ b/http/src/client/interaction.rs @@ -40,7 +40,7 @@ use twilight_validate::command::CommandValidationError; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(123).expect("non zero id"); +/// let application_id = Id::new_checked(123).expect("non zero id"); /// /// let interaction_client = client.interaction(application_id); /// diff --git a/http/src/client/mod.rs b/http/src/client/mod.rs index 996a3357c17..78b0914d0e8 100644 --- a/http/src/client/mod.rs +++ b/http/src/client/mod.rs @@ -290,7 +290,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let guild_id = Id::new(101).expect("non zero"); + /// let guild_id = Id::new_checked(101).expect("non zero"); /// let audit_log = client /// // not done /// .audit_log(guild_id) @@ -316,7 +316,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(1).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); /// /// let bans = client.bans(guild_id).exec().await?; /// # Ok(()) } @@ -348,8 +348,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(100).expect("non zero"); - /// let user_id = Id::new(200).expect("non zero"); + /// let guild_id = Id::new_checked(100).expect("non zero"); + /// let user_id = Id::new_checked(200).expect("non zero"); /// client.create_ban(guild_id, user_id) /// .delete_message_days(1)? /// .reason("memes")? @@ -379,8 +379,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(100).expect("non zero"); - /// let user_id = Id::new(200).expect("non zero"); + /// let guild_id = Id::new_checked(100).expect("non zero"); + /// let user_id = Id::new_checked(200).expect("non zero"); /// /// client.delete_ban(guild_id, user_id).exec().await?; /// # Ok(()) } @@ -407,7 +407,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new(100).expect("non zero"); + /// let channel_id = Id::new_checked(100).expect("non zero"); /// # /// let channel = client.channel(channel_id).exec().await?; /// # Ok(()) } @@ -466,8 +466,8 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); - /// let channel_id = Id::new(123).expect("non zero"); - /// let message_id = Id::new(234).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let message_id = Id::new_checked(234).expect("non zero"); /// let limit: u64 = 6; /// /// let messages = client @@ -517,10 +517,10 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// - /// let channel_id = Id::new(123).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// let allow = Permissions::VIEW_CHANNEL; /// let deny = Permissions::SEND_MESSAGES; - /// let role_id = Id::new(432).expect("non zero"); + /// let role_id = Id::new_checked(432).expect("non zero"); /// /// client.update_channel_permission(channel_id, allow, deny) /// .role(role_id) @@ -598,8 +598,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let after = Id::new(300).expect("non zero"); - /// let before = Id::new(400).expect("non zero"); + /// let after = Id::new_checked(300).expect("non zero"); + /// let before = Id::new_checked(400).expect("non zero"); /// let guilds = client.current_user_guilds() /// .after(after) /// .before(before) @@ -637,7 +637,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(100).expect("non zero"); + /// let guild_id = Id::new_checked(100).expect("non zero"); /// /// client.emojis(guild_id).exec().await?; /// # Ok(()) } @@ -660,8 +660,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(50).expect("non zero"); - /// let emoji_id = Id::new(100).expect("non zero"); + /// let guild_id = Id::new_checked(50).expect("non zero"); + /// let emoji_id = Id::new_checked(100).expect("non zero"); /// /// client.emoji(guild_id, emoji_id).exec().await?; /// # Ok(()) } @@ -885,8 +885,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(100).expect("non zero"); - /// let user_id = Id::new(3000).expect("non zero"); + /// let guild_id = Id::new_checked(100).expect("non zero"); + /// let user_id = Id::new_checked(3000).expect("non zero"); /// let members = client.guild_members(guild_id).after(user_id).exec().await?; /// # Ok(()) } /// ``` @@ -917,7 +917,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(100).expect("non zero"); + /// let guild_id = Id::new_checked(100).expect("non zero"); /// let members = client.search_guild_members(guild_id, "Wumpus") /// .limit(10)? /// .exec() @@ -995,7 +995,7 @@ impl Client { /// /// # #[tokio::main] async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let member = client.update_guild_member(Id::new(1).expect("non zero"), Id::new(2).expect("non zero")) + /// let member = client.update_guild_member(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) /// .mute(true) /// .nick(Some("pinkie pie"))? /// .exec() @@ -1044,9 +1044,9 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new(1).expect("non zero"); - /// let role_id = Id::new(2).expect("non zero"); - /// let user_id = Id::new(3).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let role_id = Id::new_checked(2).expect("non zero"); + /// let user_id = Id::new_checked(3).expect("non zero"); /// /// client.add_guild_member_role(guild_id, user_id, role_id) /// .reason("test")? @@ -1174,7 +1174,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new(123).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// let invite = client /// .create_invite(channel_id) /// .max_uses(3)? @@ -1220,7 +1220,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new(123).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// let message = client /// .create_message(channel_id) /// .content("Twilight is best pony")? @@ -1288,7 +1288,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); - /// client.update_message(Id::new(1).expect("non zero"), Id::new(2).expect("non zero")) + /// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) /// .content(Some("test update"))? /// .exec() /// .await?; @@ -1304,7 +1304,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// client.update_message(Id::new(1).expect("non zero"), Id::new(2).expect("non zero")) + /// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) /// .content(None)? /// .exec() /// .await?; @@ -1378,8 +1378,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new(123).expect("non zero"); - /// let message_id = Id::new(456).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let message_id = Id::new_checked(456).expect("non zero"); /// let emoji = RequestReactionType::Unicode { name: "🌃" }; /// /// let reaction = client @@ -1471,7 +1471,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let guild_id = Id::new(234).expect("non zero"); + /// let guild_id = Id::new_checked(234).expect("non zero"); /// /// client.create_role(guild_id) /// .color(0xd90083) @@ -1845,7 +1845,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let channel_id = Id::new(123).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// /// let webhook = client /// .create_webhook(channel_id, "Twily Bot") @@ -1893,7 +1893,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let id = Id::new(432).expect("non zero"); + /// let id = Id::new_checked(432).expect("non zero"); /// # /// let webhook = client /// .execute_webhook(id, "webhook token") @@ -1935,7 +1935,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// client.update_webhook_message(Id::new(1).expect("non zero"), "token here", Id::new(2).expect("non zero")) + /// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) /// .content(Some("new message content"))? /// .exec() /// .await?; @@ -1962,7 +1962,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); /// client - /// .delete_webhook_message(Id::new(1).expect("non zero"), "token here", Id::new(2).expect("non zero")) + /// .delete_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) /// .exec() /// .await?; /// # Ok(()) } @@ -1988,7 +1988,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let id = Id::new(123).expect("non zero"); + /// let id = Id::new_checked(123).expect("non zero"); /// let sticker = client.sticker(id).exec().await?.model().await?; /// /// println!("{:#?}", sticker); @@ -2030,7 +2030,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(1).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); /// let stickers = client /// .guild_stickers(guild_id) /// .exec() @@ -2057,8 +2057,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(1).expect("non zero"); - /// let sticker_id = Id::new(2).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let sticker_id = Id::new_checked(2).expect("non zero"); /// let sticker = client /// .guild_sticker(guild_id, sticker_id) /// .exec() @@ -2089,7 +2089,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(1).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); /// let sticker = client /// .create_guild_sticker( /// guild_id, @@ -2129,8 +2129,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(1).expect("non zero"); - /// let sticker_id = Id::new(2).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let sticker_id = Id::new_checked(2).expect("non zero"); /// let sticker = client /// .update_guild_sticker(guild_id, sticker_id) /// .description("new description")? @@ -2162,8 +2162,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new(1).expect("non zero"); - /// let sticker_id = Id::new(2).expect("non zero"); + /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let sticker_id = Id::new_checked(2).expect("non zero"); /// /// client /// .delete_guild_sticker(guild_id, sticker_id) diff --git a/http/src/request/application/command/mod.rs b/http/src/request/application/command/mod.rs index 7d09cf69a2a..9e491a3d1e8 100644 --- a/http/src/request/application/command/mod.rs +++ b/http/src/request/application/command/mod.rs @@ -68,11 +68,11 @@ mod tests { #[test] fn test_command_borrowed_from_command() { let command = Command { - application_id: Some(Id::new(1).expect("non zero")), + application_id: Some(Id::new_checked(1).expect("non zero")), default_permission: Some(true), description: "command description".to_owned(), - guild_id: Some(Id::new(2).expect("non zero")), - id: Some(Id::new(3).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Some(Id::new_checked(3).expect("non zero")), kind: CommandType::ChatInput, name: "command name".to_owned(), options: Vec::from([CommandOption::Boolean(BaseCommandOptionData { @@ -80,7 +80,7 @@ mod tests { name: "command name".to_owned(), required: true, })]), - version: Id::new(1).expect("non zero"), + version: Id::new_checked(1).expect("non zero"), }; let _ = CommandBorrowed { diff --git a/http/src/request/application/command/set_command_permissions.rs b/http/src/request/application/command/set_command_permissions.rs index 29e49b277c7..98caf78ee73 100644 --- a/http/src/request/application/command/set_command_permissions.rs +++ b/http/src/request/application/command/set_command_permissions.rs @@ -79,7 +79,7 @@ impl SortedCommand<'_> { fn new() -> Self { Self { count: 0, - id: Id::new(u64::MAX).expect("non zero"), + id: Id::new_checked(u64::MAX).expect("non zero"), permissions: OptionalCommandPermissions::new(), } } @@ -231,11 +231,11 @@ mod tests { }; fn application_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } fn guild_id() -> Id { - Id::new(2).expect("non zero") + Id::new_checked(2).expect("non zero") } #[derive(Debug, Deserialize, Eq, PartialEq)] @@ -250,7 +250,7 @@ mod tests { iter::repeat(( id, CommandPermissions { - id: CommandPermissionsType::Role(Id::new(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), permission: true, }, )) @@ -262,23 +262,23 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = &[ ( - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), CommandPermissions { - id: CommandPermissionsType::Role(Id::new(3).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(3).expect("non zero")), permission: true, }, ), ( - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), CommandPermissions { - id: CommandPermissionsType::Role(Id::new(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), permission: true, }, ), ( - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), CommandPermissions { - id: CommandPermissionsType::Role(Id::new(5).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(5).expect("non zero")), permission: true, }, ), @@ -293,22 +293,22 @@ mod tests { let expected = &[ GuildCommandPermissionDeserializable { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), permissions: Vec::from([ CommandPermissions { - id: CommandPermissionsType::Role(Id::new(3).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(3).expect("non zero")), permission: true, }, CommandPermissions { - id: CommandPermissionsType::Role(Id::new(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), permission: true, }, ]), }, GuildCommandPermissionDeserializable { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), permissions: Vec::from([CommandPermissions { - id: CommandPermissionsType::Role(Id::new(5).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(5).expect("non zero")), permission: true, }]), }, @@ -322,7 +322,7 @@ mod tests { #[test] fn test_incorrect_validation() { let http = Client::new("token".to_owned()); - let command_permissions = command_permissions(Id::new(2).expect("non zero")) + let command_permissions = command_permissions(Id::new_checked(2).expect("non zero")) .take(GUILD_COMMAND_PERMISSION_LIMIT + 1) .collect::>(); @@ -341,7 +341,7 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = (1..=SIZE) .flat_map(|id| { - command_permissions(Id::new(id as u64).expect("non zero")) + command_permissions(Id::new_checked(id as u64).expect("non zero")) .take(GUILD_COMMAND_PERMISSION_LIMIT) }) .collect::>(); @@ -361,7 +361,7 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = (1..=SIZE) - .flat_map(|id| command_permissions(Id::new(id as u64).expect("non zero")).take(3)) + .flat_map(|id| command_permissions(Id::new_checked(id as u64).expect("non zero")).take(3)) .collect::>(); let request = diff --git a/http/src/request/application/interaction/create_followup_message.rs b/http/src/request/application/interaction/create_followup_message.rs index f4208e4d2fb..badecd3e223 100644 --- a/http/src/request/application/interaction/create_followup_message.rs +++ b/http/src/request/application/interaction/create_followup_message.rs @@ -53,7 +53,7 @@ pub(crate) struct CreateFollowupMessageFields<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) @@ -213,7 +213,7 @@ impl<'a> CreateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new(1).expect("non zero"); + /// let application_id = Id::new_checked(1).expect("non zero"); /// /// let message = client /// .interaction(application_id) @@ -239,7 +239,7 @@ impl<'a> CreateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new(1).expect("non zero"); + /// let application_id = Id::new_checked(1).expect("non zero"); /// /// let message = client /// .interaction(application_id) @@ -336,7 +336,7 @@ mod tests { #[test] fn test_create_followup_message() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/delete_followup_message.rs b/http/src/request/application/interaction/delete_followup_message.rs index ea7accb0a59..2d51024a81a 100644 --- a/http/src/request/application/interaction/delete_followup_message.rs +++ b/http/src/request/application/interaction/delete_followup_message.rs @@ -21,11 +21,11 @@ use twilight_model::id::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) -/// .delete_followup_message("token here", Id::new(2).expect("non zero")) +/// .delete_followup_message("token here", Id::new_checked(2).expect("non zero")) /// .exec() /// .await?; /// # Ok(()) } @@ -96,9 +96,9 @@ mod tests { let builder = DeleteFollowupMessage::new( &client, - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), "token", - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), ); let actual = builder.try_into_request()?; diff --git a/http/src/request/application/interaction/delete_original_response.rs b/http/src/request/application/interaction/delete_original_response.rs index c7c70ecbff2..64fc7cbd79b 100644 --- a/http/src/request/application/interaction/delete_original_response.rs +++ b/http/src/request/application/interaction/delete_original_response.rs @@ -20,7 +20,7 @@ use twilight_model::id::{marker::ApplicationMarker, Id}; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) @@ -82,7 +82,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/get_followup_message.rs b/http/src/request/application/interaction/get_followup_message.rs index b88e056574d..23bb3b4dc49 100644 --- a/http/src/request/application/interaction/get_followup_message.rs +++ b/http/src/request/application/interaction/get_followup_message.rs @@ -26,11 +26,11 @@ use twilight_model::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// let response = client /// .interaction(application_id) -/// .followup_message("token here", Id::new(2).expect("non zero")) +/// .followup_message("token here", Id::new_checked(2).expect("non zero")) /// .exec() /// .await?; /// # Ok(()) } @@ -106,11 +106,11 @@ mod tests { const TOKEN: &str = "token"; fn application_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } fn message_id() -> Id { - Id::new(2).expect("non zero") + Id::new_checked(2).expect("non zero") } let client = Client::new("token".to_owned()); diff --git a/http/src/request/application/interaction/get_original_response.rs b/http/src/request/application/interaction/get_original_response.rs index 492030806ee..ad7eb34e90a 100644 --- a/http/src/request/application/interaction/get_original_response.rs +++ b/http/src/request/application/interaction/get_original_response.rs @@ -23,7 +23,7 @@ use twilight_model::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) @@ -85,7 +85,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/interaction_callback.rs b/http/src/request/application/interaction/interaction_callback.rs index 0c6ef46ec8e..e95eab024fb 100644 --- a/http/src/request/application/interaction/interaction_callback.rs +++ b/http/src/request/application/interaction/interaction_callback.rs @@ -70,8 +70,8 @@ mod tests { #[test] fn test_interaction_callback() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); - let interaction_id = Id::new(2).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); + let interaction_id = Id::new_checked(2).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/update_followup_message.rs b/http/src/request/application/interaction/update_followup_message.rs index ed5ea801dd6..ebe1ed70e6a 100644 --- a/http/src/request/application/interaction/update_followup_message.rs +++ b/http/src/request/application/interaction/update_followup_message.rs @@ -61,11 +61,11 @@ struct UpdateFollowupMessageFields<'a> { /// }; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) -/// .update_followup_message("token here", Id::new(2).expect("non zero")) +/// .update_followup_message("token here", Id::new_checked(2).expect("non zero")) /// // By creating a default set of allowed mentions, no entity can be /// // mentioned. /// .allowed_mentions(AllowedMentions::default()) @@ -201,7 +201,7 @@ impl<'a> UpdateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new(1).expect("non zero"); + /// let application_id = Id::new_checked(1).expect("non zero"); /// /// let embed = EmbedBuilder::new() /// .description("Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.") @@ -211,7 +211,7 @@ impl<'a> UpdateFollowupMessage<'a> { /// /// client /// .interaction(application_id) - /// .update_followup_message("token", Id::new(2).expect("non zero")) + /// .update_followup_message("token", Id::new_checked(2).expect("non zero")) /// .embeds(Some(&[embed]))? /// .exec() /// .await?; @@ -339,8 +339,8 @@ mod tests { #[test] fn test_update_followup_message() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); - let message_id = Id::new(2).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); + let message_id = Id::new_checked(2).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/update_original_response.rs b/http/src/request/application/interaction/update_original_response.rs index 0832ae927aa..2133e9d6b09 100644 --- a/http/src/request/application/interaction/update_original_response.rs +++ b/http/src/request/application/interaction/update_original_response.rs @@ -58,7 +58,7 @@ struct UpdateOriginalResponseFields<'a> { /// }; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new(1).expect("non zero"); +/// let application_id = Id::new_checked(1).expect("non zero"); /// /// client /// .interaction(application_id) @@ -199,7 +199,7 @@ impl<'a> UpdateOriginalResponse<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new(1).expect("non zero"); + /// let application_id = Id::new_checked(1).expect("non zero"); /// /// let embed = EmbedBuilder::new() /// .description("Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.") @@ -335,7 +335,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new(1).expect("non zero id"); + let application_id = Id::new_checked(1).expect("non zero id"); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/channel/get_channel.rs b/http/src/request/channel/get_channel.rs index e35d57a126d..b559b1773e4 100644 --- a/http/src/request/channel/get_channel.rs +++ b/http/src/request/channel/get_channel.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new(100).expect("non zero"); +/// let channel_id = Id::new_checked(100).expect("non zero"); /// /// let channel = client.channel(channel_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/channel/invite/create_invite.rs b/http/src/request/channel/invite/create_invite.rs index a9daea52f24..6d8c11d78d0 100644 --- a/http/src/request/channel/invite/create_invite.rs +++ b/http/src/request/channel/invite/create_invite.rs @@ -50,7 +50,7 @@ struct CreateInviteFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new(123).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); /// let invite = client /// .create_invite(channel_id) /// .max_uses(3)? @@ -104,7 +104,7 @@ impl<'a> CreateInvite<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let invite = client.create_invite(Id::new(1).expect("non zero")) + /// let invite = client.create_invite(Id::new_checked(1).expect("non zero")) /// .max_age(60 * 60)? /// .exec() /// .await? @@ -140,7 +140,7 @@ impl<'a> CreateInvite<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let invite = client.create_invite(Id::new(1).expect("non zero")) + /// let invite = client.create_invite(Id::new_checked(1).expect("non zero")) /// .max_uses(5)? /// .exec() /// .await? @@ -258,7 +258,7 @@ mod tests { #[test] fn test_max_age() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = CreateInvite::new(&client, Id::new(1).expect("non zero")).max_age(0)?; + let mut builder = CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_age(0)?; assert_eq!(Some(0), builder.fields.max_age); builder = builder.max_age(604_800)?; assert_eq!(Some(604_800), builder.fields.max_age); @@ -270,7 +270,7 @@ mod tests { #[test] fn test_max_uses() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = CreateInvite::new(&client, Id::new(1).expect("non zero")).max_uses(0)?; + let mut builder = CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_uses(0)?; assert_eq!(Some(0), builder.fields.max_uses); builder = builder.max_uses(100)?; assert_eq!(Some(100), builder.fields.max_uses); diff --git a/http/src/request/channel/message/create_message.rs b/http/src/request/channel/message/create_message.rs index c29ed12b3fa..a42ebc1f5b5 100644 --- a/http/src/request/channel/message/create_message.rs +++ b/http/src/request/channel/message/create_message.rs @@ -61,7 +61,7 @@ pub(crate) struct CreateMessageFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new(123).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); /// let message = client /// .create_message(channel_id) /// .content("Twilight is best pony")? diff --git a/http/src/request/channel/message/get_channel_messages.rs b/http/src/request/channel/message/get_channel_messages.rs index 4335c0724bc..3fda57d2397 100644 --- a/http/src/request/channel/message/get_channel_messages.rs +++ b/http/src/request/channel/message/get_channel_messages.rs @@ -37,8 +37,8 @@ struct GetChannelMessagesFields { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let channel_id = Id::new(123).expect("non zero"); -/// let message_id = Id::new(234).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let message_id = Id::new_checked(234).expect("non zero"); /// /// let messages = client /// .channel_messages(channel_id) diff --git a/http/src/request/channel/message/update_message.rs b/http/src/request/channel/message/update_message.rs index 50fc53d7e5d..7a8f4053bc7 100644 --- a/http/src/request/channel/message/update_message.rs +++ b/http/src/request/channel/message/update_message.rs @@ -56,7 +56,7 @@ struct UpdateMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// client.update_message(Id::new(1).expect("non zero"), Id::new(2).expect("non zero")) +/// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) /// .content(Some("test update"))? /// .exec() /// .await?; @@ -72,7 +72,7 @@ struct UpdateMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); -/// client.update_message(Id::new(1).expect("non zero"), Id::new(2).expect("non zero")) +/// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) /// .content(None)? /// .exec() /// .await?; diff --git a/http/src/request/channel/reaction/create_reaction.rs b/http/src/request/channel/reaction/create_reaction.rs index d576ad77cbb..94234fa4be1 100644 --- a/http/src/request/channel/reaction/create_reaction.rs +++ b/http/src/request/channel/reaction/create_reaction.rs @@ -26,8 +26,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new(123).expect("non zero"); -/// let message_id = Id::new(456).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let message_id = Id::new_checked(456).expect("non zero"); /// let emoji = RequestReactionType::Unicode { name: "🌃" }; /// /// let reaction = client @@ -103,8 +103,8 @@ mod tests { let builder = CreateReaction::new( &client, - Id::new(123).expect("non zero"), - Id::new(456).expect("non zero"), + Id::new_checked(123).expect("non zero"), + Id::new_checked(456).expect("non zero"), &emoji, ); let actual = builder.try_into_request()?; diff --git a/http/src/request/channel/reaction/mod.rs b/http/src/request/channel/reaction/mod.rs index 4e8863e6077..54d921b57f4 100644 --- a/http/src/request/channel/reaction/mod.rs +++ b/http/src/request/channel/reaction/mod.rs @@ -75,7 +75,7 @@ impl<'a> RequestReactionType<'a> { /// use twilight_model::id::Id; /// /// let reaction = RequestReactionType::Custom { -/// id: Id::new(123).expect("non zero"), +/// id: Id::new_checked(123).expect("non zero"), /// name: Some("rarity"), /// }; /// @@ -131,7 +131,7 @@ mod tests { #[test] fn test_display_custom_with_name() { let reaction = RequestReactionType::Custom { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), name: Some("foo"), }; @@ -141,7 +141,7 @@ mod tests { #[test] fn test_display_custom_without_name() { let reaction = RequestReactionType::Custom { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), name: None, }; diff --git a/http/src/request/channel/thread/update_thread.rs b/http/src/request/channel/thread/update_thread.rs index 003638c79b8..9b05c20eb40 100644 --- a/http/src/request/channel/thread/update_thread.rs +++ b/http/src/request/channel/thread/update_thread.rs @@ -202,7 +202,7 @@ mod tests { #[test] fn test_request() -> Result<(), Box> { let client = Client::new("token".to_string()); - let channel_id = Id::new(123).expect("non zero"); + let channel_id = Id::new_checked(123).expect("non zero"); let actual = UpdateThread::new(&client, channel_id) .rate_limit_per_user(60)? diff --git a/http/src/request/channel/update_channel_permission.rs b/http/src/request/channel/update_channel_permission.rs index a6871f31211..6f0f3746818 100644 --- a/http/src/request/channel/update_channel_permission.rs +++ b/http/src/request/channel/update_channel_permission.rs @@ -24,10 +24,10 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new(123).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); /// let allow = Permissions::VIEW_CHANNEL; /// let deny = Permissions::SEND_MESSAGES; -/// let role_id = Id::new(432).expect("non zero"); +/// let role_id = Id::new_checked(432).expect("non zero"); /// /// client.update_channel_permission(channel_id, allow, deny) /// .role(role_id) diff --git a/http/src/request/channel/update_channel_permission_configured.rs b/http/src/request/channel/update_channel_permission_configured.rs index bcbf70fa4e0..9d1b6568b86 100644 --- a/http/src/request/channel/update_channel_permission_configured.rs +++ b/http/src/request/channel/update_channel_permission_configured.rs @@ -116,10 +116,10 @@ mod tests { let client = Client::new("foo".to_owned()); let builder = UpdateChannelPermissionConfigured::new( &client, - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), Permissions::empty(), Permissions::SEND_MESSAGES, - PermissionOverwriteType::Member(Id::new(2).expect("non zero")), + PermissionOverwriteType::Member(Id::new_checked(2).expect("non zero")), ); let actual = builder .try_into_request() diff --git a/http/src/request/channel/webhook/create_webhook.rs b/http/src/request/channel/webhook/create_webhook.rs index 4614685ddc8..aabd7c285c3 100644 --- a/http/src/request/channel/webhook/create_webhook.rs +++ b/http/src/request/channel/webhook/create_webhook.rs @@ -29,7 +29,7 @@ struct CreateWebhookFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let channel_id = Id::new(123).expect("non zero"); +/// let channel_id = Id::new_checked(123).expect("non zero"); /// /// let webhook = client /// .create_webhook(channel_id, "Twily Bot") diff --git a/http/src/request/channel/webhook/delete_webhook_message.rs b/http/src/request/channel/webhook/delete_webhook_message.rs index bc3474daa1f..2632cf9922b 100644 --- a/http/src/request/channel/webhook/delete_webhook_message.rs +++ b/http/src/request/channel/webhook/delete_webhook_message.rs @@ -23,7 +23,7 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); /// client -/// .delete_webhook_message(Id::new(1).expect("non zero"), "token here", Id::new(2).expect("non zero")) +/// .delete_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) /// .reason("reason here")? /// .exec() /// .await?; @@ -118,9 +118,9 @@ mod tests { let client = Client::new("token".to_owned()); let builder = DeleteWebhookMessage::new( &client, - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), "token", - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), ); let actual = builder .try_into_request() diff --git a/http/src/request/channel/webhook/execute_webhook.rs b/http/src/request/channel/webhook/execute_webhook.rs index 27b7845833d..ad33ca48cfd 100644 --- a/http/src/request/channel/webhook/execute_webhook.rs +++ b/http/src/request/channel/webhook/execute_webhook.rs @@ -56,7 +56,7 @@ pub(crate) struct ExecuteWebhookFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let id = Id::new(432).expect("non zero"); +/// let id = Id::new_checked(432).expect("non zero"); /// /// client /// .execute_webhook(id, "webhook token") @@ -213,7 +213,7 @@ impl<'a> ExecuteWebhook<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let message = client.execute_webhook(Id::new(1).expect("non zero"), "token here") + /// let message = client.execute_webhook(Id::new_checked(1).expect("non zero"), "token here") /// .content("some content")? /// .embeds(&[EmbedBuilder::new().title("title").build()?])? /// .wait() @@ -235,7 +235,7 @@ impl<'a> ExecuteWebhook<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let message = client.execute_webhook(Id::new(1).expect("non zero"), "token here") + /// let message = client.execute_webhook(Id::new_checked(1).expect("non zero"), "token here") /// .content("some content")? /// .payload_json(br#"{ "content": "other content", "embeds": [ { "title": "title" } ] }"#) /// .wait() diff --git a/http/src/request/channel/webhook/execute_webhook_and_wait.rs b/http/src/request/channel/webhook/execute_webhook_and_wait.rs index a88a85e898c..500f3a8c8fa 100644 --- a/http/src/request/channel/webhook/execute_webhook_and_wait.rs +++ b/http/src/request/channel/webhook/execute_webhook_and_wait.rs @@ -18,7 +18,7 @@ use twilight_model::channel::Message; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let id = Id::new(432).expect("non zero"); +/// let id = Id::new_checked(432).expect("non zero"); /// /// let message = client /// .execute_webhook(id, "webhook token") diff --git a/http/src/request/channel/webhook/update_webhook_message.rs b/http/src/request/channel/webhook/update_webhook_message.rs index b2c94f5e5bb..9c7f4fc9306 100644 --- a/http/src/request/channel/webhook/update_webhook_message.rs +++ b/http/src/request/channel/webhook/update_webhook_message.rs @@ -63,7 +63,7 @@ struct UpdateWebhookMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); -/// client.update_webhook_message(Id::new(1).expect("non zero"), "token here", Id::new(2).expect("non zero")) +/// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) /// // By creating a default set of allowed mentions, no entity can be /// // mentioned. /// .allowed_mentions(AllowedMentions::default()) @@ -211,7 +211,7 @@ impl<'a> UpdateWebhookMessage<'a> { /// .url("https://twilight.rs") /// .build()?; /// - /// client.update_webhook_message(Id::new(1).expect("non zero"), "token", Id::new(2).expect("non zero")) + /// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token", Id::new_checked(2).expect("non zero")) /// .embeds(Some(&[embed]))? /// .exec() /// .await?; @@ -373,13 +373,13 @@ mod tests { let client = Client::new("token".to_owned()); let builder = UpdateWebhookMessage::new( &client, - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), "token", - Id::new(2).expect("non zero"), + Id::new_checked(2).expect("non zero"), ) .content(Some("test")) .expect("'test' content couldn't be set") - .thread_id(Id::new(3).expect("non zero")) + .thread_id(Id::new_checked(3).expect("non zero")) .reason("reason") .expect("'reason' is not a valid reason"); let actual = builder diff --git a/http/src/request/guild/ban/create_ban.rs b/http/src/request/guild/ban/create_ban.rs index aa94809b8a8..afc375207bc 100644 --- a/http/src/request/guild/ban/create_ban.rs +++ b/http/src/request/guild/ban/create_ban.rs @@ -35,8 +35,8 @@ struct CreateBanFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(100).expect("non zero"); -/// let user_id = Id::new(200).expect("non zero"); +/// let guild_id = Id::new_checked(100).expect("non zero"); +/// let user_id = Id::new_checked(200).expect("non zero"); /// client.create_ban(guild_id, user_id) /// .delete_message_days(1)? /// .reason("memes")? diff --git a/http/src/request/guild/ban/delete_ban.rs b/http/src/request/guild/ban/delete_ban.rs index 380060a6a80..34d0a4c92d7 100644 --- a/http/src/request/guild/ban/delete_ban.rs +++ b/http/src/request/guild/ban/delete_ban.rs @@ -24,8 +24,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(100).expect("non zero"); -/// let user_id = Id::new(200).expect("non zero"); +/// let guild_id = Id::new_checked(100).expect("non zero"); +/// let user_id = Id::new_checked(200).expect("non zero"); /// /// client.delete_ban(guild_id, user_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/ban/get_bans.rs b/http/src/request/guild/ban/get_bans.rs index 4a71d41f5ae..63dcdcdf14f 100644 --- a/http/src/request/guild/ban/get_bans.rs +++ b/http/src/request/guild/ban/get_bans.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); /// /// let bans = client.bans(guild_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/create_guild/builder.rs b/http/src/request/guild/create_guild/builder.rs index 56d6d78a5c9..e4295b19702 100644 --- a/http/src/request/guild/create_guild/builder.rs +++ b/http/src/request/guild/create_guild/builder.rs @@ -84,7 +84,7 @@ impl RoleFieldsBuilder { pub const COLOR_MAXIMUM: u32 = 0xff_ff_ff; fn role_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } /// Create a new default role field builder. @@ -313,7 +313,7 @@ impl TextFieldsBuilder { } Ok(Self(TextFields { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildText, name, nsfw: None, @@ -487,7 +487,7 @@ impl VoiceFieldsBuilder { Ok(Self(VoiceFields { bitrate: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildVoice, name, permission_overwrites: None, @@ -638,7 +638,7 @@ impl CategoryFieldsBuilder { Ok(Self { fields: CategoryFields { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name, kind: ChannelType::GuildCategory, permission_overwrites: None, @@ -717,9 +717,9 @@ impl GuildChannelFieldsBuilder { .iter() .rev() .find(|c| matches!(c, GuildChannelFields::Category(_))) - .map_or(Id::new(1).expect("non zero"), GuildChannelFields::id); + .map_or(Id::new_checked(1).expect("non zero"), GuildChannelFields::id); - let mut channels = channel.build(Id::new(last_id.get() + 1).expect("non zero")); + let mut channels = channel.build(Id::new_checked(last_id.get() + 1).expect("non zero")); self.0.append(&mut channels); @@ -775,7 +775,7 @@ mod tests { PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), } } @@ -802,7 +802,7 @@ mod tests { .color(0x12_34_56) .unwrap() .hoist() - .id(Id::new(2).expect("non zero")) + .id(Id::new_checked(2).expect("non zero")) .unwrap() .mentionable() .permissions(Permissions::empty()) @@ -813,7 +813,7 @@ mod tests { RoleFields { color: Some(0x12_34_56), hoist: Some(true), - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), mentionable: Some(true), name: String::from("rolename"), permissions: Some(Permissions::empty()), @@ -834,13 +834,13 @@ mod tests { voice(), VoiceFields { bitrate: Some(96_000), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), parent_id: None, user_limit: Some(40), @@ -871,14 +871,14 @@ mod tests { assert_eq!( text(), TextFields { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), permission_overwrites: Some(vec![PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), parent_id: None, rate_limit_per_user: Some(4_000), @@ -909,13 +909,13 @@ mod tests { channels.build(), vec![ GuildChannelFields::Category(CategoryFields { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildCategory, name: String::from("category"), permission_overwrites: None, }), GuildChannelFields::Text(TextFields { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), @@ -924,15 +924,15 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), - parent_id: Some(Id::new(2).expect("non zero")), + parent_id: Some(Id::new_checked(2).expect("non zero")), rate_limit_per_user: Some(4_000), topic: Some(String::from("a topic")), }), GuildChannelFields::Voice(VoiceFields { bitrate: Some(96_000), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { @@ -940,9 +940,9 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), - parent_id: Some(Id::new(2).expect("non zero")), + parent_id: Some(Id::new_checked(2).expect("non zero")), user_limit: Some(40), }), ] @@ -959,7 +959,7 @@ mod tests { channels.build(), vec![ GuildChannelFields::Text(TextFields { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), @@ -968,7 +968,7 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), parent_id: None, rate_limit_per_user: Some(4_000), @@ -976,7 +976,7 @@ mod tests { }), GuildChannelFields::Voice(VoiceFields { bitrate: Some(96_000), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { @@ -984,7 +984,7 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }]), parent_id: None, user_limit: Some(40), diff --git a/http/src/request/guild/emoji/get_emoji.rs b/http/src/request/guild/emoji/get_emoji.rs index b2a0ff4cdb8..617a8e6d65c 100644 --- a/http/src/request/guild/emoji/get_emoji.rs +++ b/http/src/request/guild/emoji/get_emoji.rs @@ -27,8 +27,8 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(50).expect("non zero"); -/// let emoji_id = Id::new(100).expect("non zero"); +/// let guild_id = Id::new_checked(50).expect("non zero"); +/// let emoji_id = Id::new_checked(100).expect("non zero"); /// /// client.emoji(guild_id, emoji_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/emoji/get_emojis.rs b/http/src/request/guild/emoji/get_emojis.rs index 3c22546686c..622080c74ff 100644 --- a/http/src/request/guild/emoji/get_emojis.rs +++ b/http/src/request/guild/emoji/get_emojis.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(100).expect("non zero"); +/// let guild_id = Id::new_checked(100).expect("non zero"); /// /// client.emojis(guild_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/get_audit_log.rs b/http/src/request/guild/get_audit_log.rs index 9e6209a9643..f5c1213ce89 100644 --- a/http/src/request/guild/get_audit_log.rs +++ b/http/src/request/guild/get_audit_log.rs @@ -35,7 +35,7 @@ struct GetAuditLogFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("token".to_owned()); /// -/// let guild_id = Id::new(101).expect("non zero"); +/// let guild_id = Id::new_checked(101).expect("non zero"); /// let audit_log = client /// .audit_log(guild_id) /// .exec() diff --git a/http/src/request/guild/get_guild_prune_count.rs b/http/src/request/guild/get_guild_prune_count.rs index ab386497bc7..3e61c378edd 100644 --- a/http/src/request/guild/get_guild_prune_count.rs +++ b/http/src/request/guild/get_guild_prune_count.rs @@ -100,7 +100,7 @@ mod test { fn test_days() { fn days_valid(days: u64) -> bool { let client = Client::new("".to_owned()); - let count = GetGuildPruneCount::new(&client, Id::new(1).expect("non zero")); + let count = GetGuildPruneCount::new(&client, Id::new_checked(1).expect("non zero")); let days_result = count.days(days); days_result.is_ok() } diff --git a/http/src/request/guild/member/add_role_to_member.rs b/http/src/request/guild/member/add_role_to_member.rs index 18da9e70f1e..f3928613e06 100644 --- a/http/src/request/guild/member/add_role_to_member.rs +++ b/http/src/request/guild/member/add_role_to_member.rs @@ -24,9 +24,9 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); -/// let role_id = Id::new(2).expect("non zero"); -/// let user_id = Id::new(3).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let role_id = Id::new_checked(2).expect("non zero"); +/// let user_id = Id::new_checked(3).expect("non zero"); /// /// client.add_guild_member_role(guild_id, user_id, role_id) /// .reason("test")? diff --git a/http/src/request/guild/member/get_guild_members.rs b/http/src/request/guild/member/get_guild_members.rs index c69129ae8d0..b2b2d2c888b 100644 --- a/http/src/request/guild/member/get_guild_members.rs +++ b/http/src/request/guild/member/get_guild_members.rs @@ -36,8 +36,8 @@ struct GetGuildMembersFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(100).expect("non zero"); -/// let user_id = Id::new(3000).expect("non zero"); +/// let guild_id = Id::new_checked(100).expect("non zero"); +/// let user_id = Id::new_checked(3000).expect("non zero"); /// let members = client.guild_members(guild_id).after(user_id).exec().await?; /// # Ok(()) } /// ``` diff --git a/http/src/request/guild/member/search_guild_members.rs b/http/src/request/guild/member/search_guild_members.rs index 7f47e940d37..05cdc4f45ec 100644 --- a/http/src/request/guild/member/search_guild_members.rs +++ b/http/src/request/guild/member/search_guild_members.rs @@ -31,7 +31,7 @@ struct SearchGuildMembersFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(100).expect("non zero"); +/// let guild_id = Id::new_checked(100).expect("non zero"); /// let members = client.search_guild_members(guild_id, "Wumpus") /// .limit(10)? /// .exec() diff --git a/http/src/request/guild/member/update_guild_member.rs b/http/src/request/guild/member/update_guild_member.rs index 0351a3c0636..d138dadffc9 100644 --- a/http/src/request/guild/member/update_guild_member.rs +++ b/http/src/request/guild/member/update_guild_member.rs @@ -204,11 +204,11 @@ mod tests { }; fn guild_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } fn user_id() -> Id { - Id::new(1).expect("non zero") + Id::new_checked(1).expect("non zero") } #[test] diff --git a/http/src/request/guild/role/create_role.rs b/http/src/request/guild/role/create_role.rs index b28cc56a4a7..fed789fabb5 100644 --- a/http/src/request/guild/role/create_role.rs +++ b/http/src/request/guild/role/create_role.rs @@ -40,7 +40,7 @@ struct CreateRoleFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let guild_id = Id::new(234).expect("non zero"); +/// let guild_id = Id::new_checked(234).expect("non zero"); /// /// client.create_role(guild_id) /// .color(0xd90083) diff --git a/http/src/request/guild/sticker/create_guild_sticker.rs b/http/src/request/guild/sticker/create_guild_sticker.rs index 1d1c4fd29b5..6c8151df0d2 100644 --- a/http/src/request/guild/sticker/create_guild_sticker.rs +++ b/http/src/request/guild/sticker/create_guild_sticker.rs @@ -33,7 +33,7 @@ struct CreateGuildStickerFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); /// let sticker = client /// .create_guild_sticker( /// guild_id, diff --git a/http/src/request/guild/sticker/delete_guild_sticker.rs b/http/src/request/guild/sticker/delete_guild_sticker.rs index e1be16fff29..a7d70ce9334 100644 --- a/http/src/request/guild/sticker/delete_guild_sticker.rs +++ b/http/src/request/guild/sticker/delete_guild_sticker.rs @@ -22,8 +22,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); -/// let sticker_id = Id::new(2).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let sticker_id = Id::new_checked(2).expect("non zero"); /// /// client /// .delete_guild_sticker(guild_id, sticker_id) diff --git a/http/src/request/guild/sticker/get_guild_sticker.rs b/http/src/request/guild/sticker/get_guild_sticker.rs index f884651e177..35c9d4f9eec 100644 --- a/http/src/request/guild/sticker/get_guild_sticker.rs +++ b/http/src/request/guild/sticker/get_guild_sticker.rs @@ -25,8 +25,8 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); -/// let sticker_id = Id::new(2).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let sticker_id = Id::new_checked(2).expect("non zero"); /// let sticker = client /// .guild_sticker(guild_id, sticker_id) /// .exec() diff --git a/http/src/request/guild/sticker/get_guild_stickers.rs b/http/src/request/guild/sticker/get_guild_stickers.rs index 918ad2f787c..bf5834f5562 100644 --- a/http/src/request/guild/sticker/get_guild_stickers.rs +++ b/http/src/request/guild/sticker/get_guild_stickers.rs @@ -22,7 +22,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); /// let stickers = client /// .guild_stickers(guild_id) /// .exec() diff --git a/http/src/request/guild/sticker/update_guild_sticker.rs b/http/src/request/guild/sticker/update_guild_sticker.rs index 67ff3252918..d7c4a5a3532 100644 --- a/http/src/request/guild/sticker/update_guild_sticker.rs +++ b/http/src/request/guild/sticker/update_guild_sticker.rs @@ -37,8 +37,8 @@ struct UpdateGuildStickerFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new(1).expect("non zero"); -/// let sticker_id = Id::new(2).expect("non zero"); +/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let sticker_id = Id::new_checked(2).expect("non zero"); /// let sticker = client /// .update_guild_sticker(guild_id, sticker_id) /// .description("new description")? diff --git a/http/src/request/sticker/get_sticker.rs b/http/src/request/sticker/get_sticker.rs index cb47af67540..fd11b5c9bee 100644 --- a/http/src/request/sticker/get_sticker.rs +++ b/http/src/request/sticker/get_sticker.rs @@ -22,7 +22,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let id = Id::new(123).expect("non zero"); +/// let id = Id::new_checked(123).expect("non zero"); /// let sticker = client.sticker(id).exec().await?.model().await?; /// # Ok(()) } /// ``` diff --git a/http/src/request/try_into_request.rs b/http/src/request/try_into_request.rs index 6bedf53fdd3..7e1caff1041 100644 --- a/http/src/request/try_into_request.rs +++ b/http/src/request/try_into_request.rs @@ -267,7 +267,7 @@ use crate::error::Error; /// use twilight_model::{channel::Message, id::Id}; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let channel_id = Id::new(1).expect("non zero"); +/// let channel_id = Id::new_checked(1).expect("non zero"); /// let builder = client.create_message(channel_id) /// .content("This is a test message!")? /// .tts(false); @@ -321,7 +321,7 @@ mod tests { #[test] fn test_conversion() -> Result<(), Box> { let client = Client::new("token".to_owned()); - let channel_id = Id::new(1).expect("non zero"); + let channel_id = Id::new_checked(1).expect("non zero"); let builder = client.create_message(channel_id).content("test")?; let request = builder.try_into_request()?; diff --git a/http/src/request/user/get_current_user_guilds.rs b/http/src/request/user/get_current_user_guilds.rs index 72a04525fff..9956487b45f 100644 --- a/http/src/request/user/get_current_user_guilds.rs +++ b/http/src/request/user/get_current_user_guilds.rs @@ -34,8 +34,8 @@ struct GetCurrentUserGuildsFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let after = Id::new(300).expect("non zero"); -/// let before = Id::new(400).expect("non zero"); +/// let after = Id::new_checked(300).expect("non zero"); +/// let before = Id::new_checked(400).expect("non zero"); /// let guilds = client.current_user_guilds() /// .after(after) /// .before(before) diff --git a/http/src/response/future.rs b/http/src/response/future.rs index db78284fc0f..52f21f7e394 100644 --- a/http/src/response/future.rs +++ b/http/src/response/future.rs @@ -330,8 +330,8 @@ impl ResponseFuture { /// use twilight_http::{error::ErrorType, Client}; /// use twilight_model::id::{ChannelId, MessageId}; /// - /// let channel_id = ChannelId::new(1).expect("non zero id"); - /// let message_id = MessageId::new(2).expect("non zero id"); + /// let channel_id = ChannelId::new_checked(1).expect("non zero id"); + /// let message_id = MessageId::new_checked(2).expect("non zero id"); /// /// let channels_ignored = { /// let mut map = HashSet::new(); diff --git a/http/src/response/mod.rs b/http/src/response/mod.rs index 1822da63fdd..c4af0d2b523 100644 --- a/http/src/response/mod.rs +++ b/http/src/response/mod.rs @@ -18,7 +18,7 @@ //! ```no_run //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { -//! # let user_id = twilight_model::id::Id::new(1).expect("non zero"); +//! # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); //! use std::env; //! use twilight_http::Client; //! @@ -165,7 +165,7 @@ pub enum DeserializeBodyErrorType { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let user_id = twilight_model::id::Id::new(1).expect("non zero"); +/// # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -221,7 +221,7 @@ impl Response { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// # let user_id = twilight_model::id::Id::new(1).expect("non zero"); + /// # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -442,7 +442,7 @@ impl Response { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new(1).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -495,8 +495,8 @@ impl<'a> Iterator for HeaderIter<'a> { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new(1).expect("non zero"); -/// # let message_id = twilight_model::id::Id::new(2).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let message_id = twilight_model::id::Id::new_checked(2).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -541,8 +541,8 @@ impl Future for BytesFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new(1).expect("non zero"); -/// # let emoji_id = twilight_model::id::Id::new(2).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let emoji_id = twilight_model::id::Id::new_checked(2).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -603,8 +603,8 @@ impl Future for ModelFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new(1).expect("non zero"); -/// # let user_id = twilight_model::id::Id::new(2).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let user_id = twilight_model::id::Id::new_checked(2).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -680,7 +680,7 @@ impl Future for MemberFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new(1).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// @@ -759,8 +759,8 @@ impl Future for MemberListFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new(1).expect("non zero"); -/// # let message_id = twilight_model::id::Id::new(2).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let message_id = twilight_model::id::Id::new_checked(2).expect("non zero"); /// use std::env; /// use twilight_http::Client; /// diff --git a/http/src/routing/route_display.rs b/http/src/routing/route_display.rs index e4ad6d1ecad..1692e3df526 100644 --- a/http/src/routing/route_display.rs +++ b/http/src/routing/route_display.rs @@ -1145,7 +1145,7 @@ mod tests { fn emoji() -> RequestReactionType<'static> { RequestReactionType::Custom { - id: Id::new(EMOJI_ID).expect("non zero id"), + id: Id::new_checked(EMOJI_ID).expect("non zero id"), name: None, } } @@ -2922,7 +2922,7 @@ mod tests { #[test] fn test_create_guild_prune_include_one_role() { - let include_roles = [Id::new(1).expect("non zero id")]; + let include_roles = [Id::new_checked(1).expect("non zero id")]; let route = Route::CreateGuildPrune { compute_prune_count: None, @@ -2942,8 +2942,8 @@ mod tests { #[test] fn test_create_guild_prune_include_two_roles() { let include_roles = [ - Id::new(1).expect("non zero id"), - Id::new(2).expect("non zero id"), + Id::new_checked(1).expect("non zero id"), + Id::new_checked(2).expect("non zero id"), ]; let route = Route::CreateGuildPrune { @@ -2964,8 +2964,8 @@ mod tests { #[test] fn test_create_guild_prune_all() { let include_roles = [ - Id::new(1).expect("non zero id"), - Id::new(2).expect("non zero id"), + Id::new_checked(1).expect("non zero id"), + Id::new_checked(2).expect("non zero id"), ]; let route = Route::CreateGuildPrune { diff --git a/lavalink/src/player.rs b/lavalink/src/player.rs index 5197f5e1e18..01cef972012 100644 --- a/lavalink/src/player.rs +++ b/lavalink/src/player.rs @@ -117,7 +117,7 @@ impl Player { /// use twilight_lavalink::{model::{Play, Pause}, Lavalink}; /// # use twilight_model::id::Id; /// # fn main() -> Result<(), Box> { - /// # let (guild_id, user_id) = (Id::new(1).expect("non zero"), Id::new(2).expect("non zero")); + /// # let (guild_id, user_id) = (Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")); /// # let track = String::new(); /// /// let lavalink = Lavalink::new(user_id, 10); @@ -173,7 +173,7 @@ impl Player { if channel_id == 0 { None } else { - Some(Id::new(channel_id).expect("non zero")) + Some(Id::new_checked(channel_id).expect("non zero")) } } diff --git a/mention/README.md b/mention/README.md index af2f1025007..98851d8549a 100644 --- a/mention/README.md +++ b/mention/README.md @@ -18,7 +18,7 @@ Create a mention formatter for a user ID, and then format it in a message: use twilight_mention::Mention; use twilight_model::id::{marker::UserMarker, Id}; -let user_id = Id::::new(123).expect("non zero"); +let user_id = Id::::new_checked(123).expect("non zero"); let message = format!("Hey there, {}!", user_id.mention()); ``` diff --git a/mention/benches/fmt.rs b/mention/benches/fmt.rs index 3a496b5c17f..fab61424e74 100644 --- a/mention/benches/fmt.rs +++ b/mention/benches/fmt.rs @@ -13,7 +13,7 @@ fn format_id(input: &mut String, formatter: &T) { fn criterion_benchmark(c: &mut Criterion) { c.bench_function("format channel id", |b| { let mut string = String::new(); - let formatter = Id::::new(999_999_999_999_999_999) + let formatter = Id::::new_checked(999_999_999_999_999_999) .expect("non zero") .mention(); @@ -21,7 +21,7 @@ fn criterion_benchmark(c: &mut Criterion) { }); c.bench_function("format emoji id", |b| { let mut string = String::new(); - let formatter = Id::::new(999_999_999_999_999_999) + let formatter = Id::::new_checked(999_999_999_999_999_999) .expect("non zero") .mention(); @@ -29,7 +29,7 @@ fn criterion_benchmark(c: &mut Criterion) { }); c.bench_function("format role id", |b| { let mut string = String::new(); - let formatter = Id::::new(999_999_999_999_999_999) + let formatter = Id::::new_checked(999_999_999_999_999_999) .expect("non zero") .mention(); @@ -37,7 +37,7 @@ fn criterion_benchmark(c: &mut Criterion) { }); c.bench_function("format user id", |b| { let mut string = String::new(); - let formatter = Id::::new(999_999_999_999_999_999) + let formatter = Id::::new_checked(999_999_999_999_999_999) .expect("non zero") .mention(); diff --git a/mention/src/fmt.rs b/mention/src/fmt.rs index 1cdcefc3d8f..a24a3e28030 100644 --- a/mention/src/fmt.rs +++ b/mention/src/fmt.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// use twilight_mention::Mention; /// use twilight_model::id::{marker::UserMarker, Id}; /// -/// assert_eq!("<@123>", Id::::new(123).expect("non zero").mention().to_string()); +/// assert_eq!("<@123>", Id::::new_checked(123).expect("non zero").mention().to_string()); /// ``` #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct MentionFormat(T); @@ -99,7 +99,7 @@ impl Display for MentionFormat> { /// use twilight_mention::Mention; /// use twilight_model::id::{marker::ChannelMarker, Id}; /// -/// let id = Id::::new(123).expect("non zero"); +/// let id = Id::::new_checked(123).expect("non zero"); /// assert_eq!("<#123>", id.mention().to_string()); /// ``` pub trait Mention { @@ -295,7 +295,7 @@ mod tests { fn test_mention_format_channel_id() { assert_eq!( "<#123>", - Id::::new(123) + Id::::new_checked(123) .expect("non zero") .mention() .to_string() @@ -306,7 +306,7 @@ mod tests { fn test_mention_format_emoji_id() { assert_eq!( "<:emoji:123>", - Id::::new(123) + Id::::new_checked(123) .expect("non zero") .mention() .to_string() @@ -317,7 +317,7 @@ mod tests { fn test_mention_format_role_id() { assert_eq!( "<@&123>", - Id::::new(123) + Id::::new_checked(123) .expect("non zero") .mention() .to_string() @@ -344,7 +344,7 @@ mod tests { fn test_mention_format_user_id() { assert_eq!( "<@123>", - Id::::new(123) + Id::::new_checked(123) .expect("non zero") .mention() .to_string() diff --git a/mention/src/lib.rs b/mention/src/lib.rs index e202c6e3b94..d4f752b6362 100644 --- a/mention/src/lib.rs +++ b/mention/src/lib.rs @@ -16,7 +16,7 @@ //! use twilight_mention::Mention; //! use twilight_model::id::{marker::UserMarker, Id}; //! -//! let user_id = Id::::new(123).expect("non zero"); +//! let user_id = Id::::new_checked(123).expect("non zero"); //! let message = format!("Hey there, {}!", user_id.mention()); //! ``` //! diff --git a/mention/src/parse/impl.rs b/mention/src/parse/impl.rs index 1078e1f8f7f..a9b55bf415c 100644 --- a/mention/src/parse/impl.rs +++ b/mention/src/parse/impl.rs @@ -35,11 +35,11 @@ pub trait ParseMention: private::Sealed { /// /// # fn main() -> Result<(), Box> { /// assert_eq!( - /// Id::::new(123).expect("non zero"), + /// Id::::new_checked(123).expect("non zero"), /// Id::parse("<#123>")?, /// ); /// assert_eq!( - /// Id::::new(456).expect("non zero"), + /// Id::::new_checked(456).expect("non zero"), /// Id::parse("<@456>")?, /// ); /// assert!(Id::::parse("not a mention").is_err()); @@ -388,7 +388,7 @@ mod tests { #[test] fn test_parse_channel_id() { assert_eq!( - Id::::new(123).expect("non zero"), + Id::::new_checked(123).expect("non zero"), Id::parse("<#123>").unwrap() ); assert_eq!( @@ -403,7 +403,7 @@ mod tests { #[test] fn test_parse_emoji_id() { assert_eq!( - Id::::new(123).expect("non zero"), + Id::::new_checked(123).expect("non zero"), Id::parse("<:name:123>").unwrap() ); assert_eq!( @@ -418,19 +418,19 @@ mod tests { #[test] fn test_parse_mention_type() { assert_eq!( - MentionType::Channel(Id::new(123).expect("non zero")), + MentionType::Channel(Id::new_checked(123).expect("non zero")), MentionType::parse("<#123>").unwrap() ); assert_eq!( - MentionType::Emoji(Id::new(123).expect("non zero")), + MentionType::Emoji(Id::new_checked(123).expect("non zero")), MentionType::parse("<:name:123>").unwrap() ); assert_eq!( - MentionType::Role(Id::new(123).expect("non zero")), + MentionType::Role(Id::new_checked(123).expect("non zero")), MentionType::parse("<@&123>").unwrap() ); assert_eq!( - MentionType::User(Id::new(123).expect("non zero")), + MentionType::User(Id::new_checked(123).expect("non zero")), MentionType::parse("<@123>").unwrap() ); assert_eq!( @@ -445,7 +445,7 @@ mod tests { #[test] fn test_parse_role_id() { assert_eq!( - Id::::new(123).expect("non zero"), + Id::::new_checked(123).expect("non zero"), Id::parse("<@&123>").unwrap() ); assert_eq!( @@ -475,7 +475,7 @@ mod tests { #[test] fn test_parse_user_id() { assert_eq!( - Id::::new(123).expect("non zero"), + Id::::new_checked(123).expect("non zero"), Id::parse("<@123>").unwrap() ); assert_eq!( diff --git a/mention/src/parse/iter.rs b/mention/src/parse/iter.rs index e3ecf3dd785..b1216cc6685 100644 --- a/mention/src/parse/iter.rs +++ b/mention/src/parse/iter.rs @@ -128,7 +128,7 @@ mod tests { #[test] fn test_iter_channel_id() { let mut iter = Id::::iter("<#123>"); - assert_eq!(Id::new(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); assert!(iter.next().is_none()); } @@ -136,9 +136,9 @@ mod tests { fn test_iter_multiple_ids() { let buf = "one <@123>two<#456><@789> ----"; let mut iter = Id::::iter(buf); - assert_eq!(Id::new(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); let (mention, start, end) = iter.next().unwrap(); - assert_eq!(Id::new(789).expect("non zero"), mention); + assert_eq!(Id::new_checked(789).expect("non zero"), mention); assert_eq!(19, start); assert_eq!(24, end); assert!(iter.next().is_none()); @@ -147,8 +147,8 @@ mod tests { #[test] fn test_iter_emoji_ids() { let mut iter = Id::::iter("some <:name:123> emojis <:emoji:456>"); - assert_eq!(Id::new(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); assert!(iter.next().is_none()); } @@ -156,23 +156,23 @@ mod tests { fn test_iter_mention_type() { let mut iter = MentionType::iter("<#12><:name:34><@&56><@!78><@90>"); assert_eq!( - MentionType::Channel(Id::new(12).expect("non zero")), + MentionType::Channel(Id::new_checked(12).expect("non zero")), iter.next().unwrap().0 ); assert_eq!( - MentionType::Emoji(Id::new(34).expect("non zero")), + MentionType::Emoji(Id::new_checked(34).expect("non zero")), iter.next().unwrap().0 ); assert_eq!( - MentionType::Role(Id::new(56).expect("non zero")), + MentionType::Role(Id::new_checked(56).expect("non zero")), iter.next().unwrap().0 ); assert_eq!( - MentionType::User(Id::new(78).expect("non zero")), + MentionType::User(Id::new_checked(78).expect("non zero")), iter.next().unwrap().0 ); assert_eq!( - MentionType::User(Id::new(90).expect("non zero")), + MentionType::User(Id::new_checked(90).expect("non zero")), iter.next().unwrap().0 ); assert!(iter.next().is_none()); @@ -182,7 +182,7 @@ mod tests { fn test_iter_mention_type_with_timestamp() { let mut iter = MentionType::iter("<#12> "); assert_eq!( - MentionType::Channel(Id::new(12).expect("non zero")), + MentionType::Channel(Id::new_checked(12).expect("non zero")), iter.next().unwrap().0 ); assert_eq!( @@ -199,8 +199,8 @@ mod tests { #[test] fn test_iter_role_ids() { let mut iter = Id::::iter("some <@&123> roles <@&456>"); - assert_eq!(Id::new(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); assert!(iter.next().is_none()); } @@ -218,8 +218,8 @@ mod tests { #[test] fn test_iter_user_ids() { let mut iter = Id::::iter("some <@123>users<@456>"); - assert_eq!(Id::new(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); assert!(iter.next().is_none()); } diff --git a/mention/src/parse/mod.rs b/mention/src/parse/mod.rs index 925d327dae4..2ac2997b933 100644 --- a/mention/src/parse/mod.rs +++ b/mention/src/parse/mod.rs @@ -22,8 +22,8 @@ //! }; //! //! # fn main() -> Result<(), Box> { -//! assert_eq!(Id::::new(123).expect("non zero"), Id::parse("<:name:123>")?); -//! assert_eq!(Id::::new(456).expect("non zero"), Id::parse("<@&456>")?); +//! assert_eq!(Id::::new_checked(123).expect("non zero"), Id::parse("<:name:123>")?); +//! assert_eq!(Id::::new_checked(456).expect("non zero"), Id::parse("<@&456>")?); //! assert!(Id::::parse("<#notamention>").is_err()); //! # Ok(()) } //! ``` @@ -98,15 +98,15 @@ use twilight_model::id::{ /// /// # fn main() -> Result<(), Box> { /// assert_eq!( -/// MentionType::Channel(Id::::new(123).expect("non zero")), +/// MentionType::Channel(Id::::new_checked(123).expect("non zero")), /// MentionType::parse("<#123>")?, /// ); /// assert_eq!( -/// MentionType::Role(Id::::new(123).expect("non zero")), +/// MentionType::Role(Id::::new_checked(123).expect("non zero")), /// MentionType::parse("<@&123>")?, /// ); /// assert_eq!( -/// MentionType::User(Id::::new(123).expect("non zero")), +/// MentionType::User(Id::::new_checked(123).expect("non zero")), /// MentionType::parse("<@!123>")?, /// ); /// diff --git a/model/src/application/command/option.rs b/model/src/application/command/option.rs index a7f7cd3773f..3ae8f926320 100644 --- a/model/src/application/command/option.rs +++ b/model/src/application/command/option.rs @@ -672,11 +672,11 @@ mod tests { #[allow(clippy::too_many_lines)] fn test_command_option_full() { let value = Command { - application_id: Some(Id::new(100).expect("non zero")), + application_id: Some(Id::new_checked(100).expect("non zero")), default_permission: Some(true), description: "this command is a test".into(), - guild_id: Some(Id::new(300).expect("non zero")), - id: Some(Id::new(200).expect("non zero")), + guild_id: Some(Id::new_checked(300).expect("non zero")), + id: Some(Id::new_checked(200).expect("non zero")), kind: CommandType::ChatInput, name: "test command".into(), options: Vec::from([CommandOption::SubCommandGroup(OptionsCommandOptionData { @@ -756,7 +756,7 @@ mod tests { ]), })]), })]), - version: Id::new(1).expect("non zero"), + version: Id::new_checked(1).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/application/command/permissions.rs b/model/src/application/command/permissions.rs index 95d63c1f55b..c10e2c5fb7f 100644 --- a/model/src/application/command/permissions.rs +++ b/model/src/application/command/permissions.rs @@ -102,7 +102,7 @@ mod tests { #[test] fn test_command_permissions() { let value = CommandPermissions { - id: CommandPermissionsType::Role(Id::new(100).expect("non zero")), + id: CommandPermissionsType::Role(Id::new_checked(100).expect("non zero")), permission: true, }; diff --git a/model/src/application/interaction/application_command/data/mod.rs b/model/src/application/interaction/application_command/data/mod.rs index 924118173bd..3d918b80a4a 100644 --- a/model/src/application/interaction/application_command/data/mod.rs +++ b/model/src/application/interaction/application_command/data/mod.rs @@ -370,7 +370,7 @@ mod tests { #[test] fn no_options() { let value = CommandData { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "permissions".to_owned(), options: Vec::new(), resolved: None, @@ -395,7 +395,7 @@ mod tests { #[test] fn subcommand_without_option() { let value = CommandData { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "photo".to_owned(), options: Vec::from([CommandDataOption { focused: false, diff --git a/model/src/application/interaction/application_command/data/resolved.rs b/model/src/application/interaction/application_command/data/resolved.rs index c682312423d..c02497e1feb 100644 --- a/model/src/application/interaction/application_command/data/resolved.rs +++ b/model/src/application/interaction/application_command/data/resolved.rs @@ -84,9 +84,9 @@ mod tests { let value = CommandInteractionDataResolved { channels: IntoIterator::into_iter([( - Id::new(100).expect("non zero"), + Id::new_checked(100).expect("non zero"), InteractionChannel { - id: Id::new(100).expect("non zero"), + id: Id::new_checked(100).expect("non zero"), kind: ChannelType::GuildText, name: "channel name".into(), parent_id: None, @@ -96,7 +96,7 @@ mod tests { )]) .collect(), members: IntoIterator::into_iter([( - Id::new(300).expect("non zero"), + Id::new_checked(300).expect("non zero"), InteractionMember { avatar: None, communication_disabled_until: None, @@ -110,7 +110,7 @@ mod tests { )]) .collect(), messages: IntoIterator::into_iter([( - Id::new(4).expect("non zero"), + Id::new_checked(4).expect("non zero"), Message { activity: None, application: None, @@ -124,7 +124,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -133,14 +133,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -164,7 +164,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "sticker name".to_owned(), }], referenced_message: None, @@ -176,12 +176,12 @@ mod tests { )]) .collect(), roles: IntoIterator::into_iter([( - Id::new(400).expect("non zero"), + Id::new_checked(400).expect("non zero"), Role { color: 0, hoist: true, icon: None, - id: Id::new(400).expect("non zero"), + id: Id::new_checked(400).expect("non zero"), managed: false, mentionable: true, name: "test".to_owned(), @@ -193,7 +193,7 @@ mod tests { )]) .collect(), users: IntoIterator::into_iter([( - Id::new(300).expect("non zero"), + Id::new_checked(300).expect("non zero"), User { accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), @@ -202,7 +202,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new(300).expect("non zero"), + id: Id::new_checked(300).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/application/interaction/message_component/mod.rs b/model/src/application/interaction/message_component/mod.rs index 361c5421e90..f911f15dba5 100644 --- a/model/src/application/interaction/message_component/mod.rs +++ b/model/src/application/interaction/message_component/mod.rs @@ -137,21 +137,21 @@ mod tests { #[test] fn test_author_id() -> Result<(), TimestampParseError> { fn user_id() -> Id { - Id::new(7).expect("non zero") + Id::new_checked(7).expect("non zero") } let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?; let in_guild = MessageComponentInteraction { - application_id: Id::new(1).expect("non zero"), - channel_id: Id::new(2).expect("non zero"), + application_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), data: MessageComponentInteractionData { custom_id: "foo".to_owned(), component_type: ComponentType::Button, values: Vec::from(["bar".to_owned()]), }, - guild_id: Some(Id::new(3).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(3).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), kind: InteractionType::MessageComponent, member: Some(PartialMember { avatar: None, @@ -171,14 +171,14 @@ mod tests { application_id: None, attachments: Vec::new(), author: user(user_id()), - channel_id: Id::new(5).expect("non zero"), + channel_id: Id::new_checked(5).expect("non zero"), components: Vec::new(), content: String::new(), edited_timestamp: None, embeds: Vec::new(), flags: None, - guild_id: Some(Id::new(3).expect("non zero")), - id: Id::new(6).expect("non zero"), + guild_id: Some(Id::new_checked(3).expect("non zero")), + id: Id::new_checked(6).expect("non zero"), interaction: None, kind: MessageType::Regular, member: None, diff --git a/model/src/application/interaction/mod.rs b/model/src/application/interaction/mod.rs index 3bcf07cd302..eafcd92faf4 100644 --- a/model/src/application/interaction/mod.rs +++ b/model/src/application/interaction/mod.rs @@ -344,20 +344,20 @@ mod test { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = Interaction::ApplicationCommand(Box::new(ApplicationCommand { - application_id: Id::new(100).expect("non zero"), - channel_id: Id::new(200).expect("non zero"), + application_id: Id::new_checked(100).expect("non zero"), + channel_id: Id::new_checked(200).expect("non zero"), data: CommandData { - id: Id::new(300).expect("non zero"), + id: Id::new_checked(300).expect("non zero"), name: "command name".into(), options: Vec::from([CommandDataOption { focused: false, name: "member".into(), - value: CommandOptionValue::User(Id::new(600).expect("non zero")), + value: CommandOptionValue::User(Id::new_checked(600).expect("non zero")), }]), resolved: Some(CommandInteractionDataResolved { channels: HashMap::new(), members: IntoIterator::into_iter([( - Id::new(600).expect("non zero"), + Id::new_checked(600).expect("non zero"), InteractionMember { avatar: None, communication_disabled_until: None, @@ -373,7 +373,7 @@ mod test { messages: HashMap::new(), roles: HashMap::new(), users: IntoIterator::into_iter([( - Id::new(600).expect("non zero"), + Id::new_checked(600).expect("non zero"), User { accent_color: None, avatar: Some("avatar string".into()), @@ -382,7 +382,7 @@ mod test { discriminator: 1111, email: None, flags: None, - id: Id::new(600).expect("non zero"), + id: Id::new_checked(600).expect("non zero"), locale: None, mfa_enabled: None, name: "username".into(), @@ -395,8 +395,8 @@ mod test { .collect(), }), }, - guild_id: Some(Id::new(400).expect("non zero")), - id: Id::new(500).expect("non zero"), + guild_id: Some(Id::new_checked(400).expect("non zero")), + id: Id::new_checked(500).expect("non zero"), kind: InteractionType::ApplicationCommand, member: Some(PartialMember { avatar: None, @@ -416,7 +416,7 @@ mod test { discriminator: 1111, email: None, flags: None, - id: Id::new(600).expect("non zero"), + id: Id::new_checked(600).expect("non zero"), locale: None, mfa_enabled: None, name: "username".into(), diff --git a/model/src/channel/attachment.rs b/model/src/channel/attachment.rs index 9e6fb6ad4a2..7add75687da 100644 --- a/model/src/channel/attachment.rs +++ b/model/src/channel/attachment.rs @@ -69,7 +69,7 @@ mod tests { filename: "a.png".to_owned(), description: Some("a image".to_owned()), height: Some(184), - id: Id::new(700_000_000_000_000_000).expect("non zero"), + id: Id::new_checked(700_000_000_000_000_000).expect("non zero"), proxy_url: "https://cdn.example.com/1.png".to_owned(), size: 13_593, url: "https://example.com/1.png".to_owned(), diff --git a/model/src/channel/category_channel.rs b/model/src/channel/category_channel.rs index fcf39eedb04..2b4b0feb475 100644 --- a/model/src/channel/category_channel.rs +++ b/model/src/channel/category_channel.rs @@ -28,8 +28,8 @@ mod tests { #[test] fn test_category_channel() { let value = CategoryChannel { - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildCategory, name: "category".to_owned(), permission_overwrites: Vec::new(), diff --git a/model/src/channel/channel_mention.rs b/model/src/channel/channel_mention.rs index cda50e4afe5..63112754f8f 100644 --- a/model/src/channel/channel_mention.rs +++ b/model/src/channel/channel_mention.rs @@ -25,8 +25,8 @@ mod tests { #[test] fn test_channel_mention() { let value = ChannelMention { - guild_id: Id::new(1).expect("non zero"), - id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildText, name: "channel".to_owned(), }; diff --git a/model/src/channel/followed_channel.rs b/model/src/channel/followed_channel.rs index f69a5af28bc..ccfdefb8a75 100644 --- a/model/src/channel/followed_channel.rs +++ b/model/src/channel/followed_channel.rs @@ -25,8 +25,8 @@ mod tests { #[test] fn test_followed_channel() { let value = FollowedChannel { - channel_id: Id::new(1).expect("non zero"), - webhook_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), + webhook_id: Id::new_checked(2).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/channel/group.rs b/model/src/channel/group.rs index ba05600b59d..81b94e0ec79 100644 --- a/model/src/channel/group.rs +++ b/model/src/channel/group.rs @@ -40,14 +40,14 @@ mod tests { #[test] fn test_group() { let value = Group { - application_id: Some(Id::new(1).expect("non zero")), + application_id: Some(Id::new_checked(1).expect("non zero")), icon: Some("icon hash".to_owned()), - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::Group, - last_message_id: Some(Id::new(3).expect("non zero")), + last_message_id: Some(Id::new_checked(3).expect("non zero")), last_pin_timestamp: None, name: Some("a group".to_owned()), - owner_id: Id::new(4).expect("non zero"), + owner_id: Id::new_checked(4).expect("non zero"), recipients: Vec::new(), }; @@ -93,14 +93,14 @@ mod tests { let timestamp = Timestamp::from_str("2021-08-10T12:21:10+00:00")?; let value = Group { - application_id: Some(Id::new(1).expect("non zero")), + application_id: Some(Id::new_checked(1).expect("non zero")), icon: Some("icon hash".to_owned()), - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::Group, - last_message_id: Some(Id::new(3).expect("non zero")), + last_message_id: Some(Id::new_checked(3).expect("non zero")), last_pin_timestamp: Some(timestamp), name: Some("a group".to_owned()), - owner_id: Id::new(4).expect("non zero"), + owner_id: Id::new_checked(4).expect("non zero"), recipients: Vec::new(), }; diff --git a/model/src/channel/message/allowed_mentions/builder.rs b/model/src/channel/message/allowed_mentions/builder.rs index 94c612ecdea..8cfb97aca6f 100644 --- a/model/src/channel/message/allowed_mentions/builder.rs +++ b/model/src/channel/message/allowed_mentions/builder.rs @@ -146,11 +146,11 @@ mod tests { let value = AllowedMentionsBuilder::new() .users() .user_ids(vec![ - Id::new(100).expect("non zero"), - Id::new(200).expect("non zero"), + Id::new_checked(100).expect("non zero"), + Id::new_checked(200).expect("non zero"), ]) .roles() - .role_ids(vec![Id::new(300).expect("non zero")]) + .role_ids(vec![Id::new_checked(300).expect("non zero")]) .build(); assert_eq!( @@ -158,10 +158,10 @@ mod tests { AllowedMentions { parse: vec![], users: vec![ - Id::new(100).expect("non zero"), - Id::new(200).expect("non zero") + Id::new_checked(100).expect("non zero"), + Id::new_checked(200).expect("non zero") ], - roles: vec![Id::new(300).expect("non zero")], + roles: vec![Id::new_checked(300).expect("non zero")], replied_user: false, }, ); diff --git a/model/src/channel/message/allowed_mentions/mod.rs b/model/src/channel/message/allowed_mentions/mod.rs index 4e1dfdc8288..f878f4f04c9 100644 --- a/model/src/channel/message/allowed_mentions/mod.rs +++ b/model/src/channel/message/allowed_mentions/mod.rs @@ -74,8 +74,8 @@ mod tests { fn test_full() { let value = AllowedMentions { parse: vec![ParseTypes::Everyone], - users: vec![Id::new(100).expect("non zero")], - roles: vec![Id::new(200).expect("non zero")], + users: vec![Id::new_checked(100).expect("non zero")], + roles: vec![Id::new_checked(200).expect("non zero")], replied_user: true, }; diff --git a/model/src/channel/message/application.rs b/model/src/channel/message/application.rs index afca90f7a38..066dc42f549 100644 --- a/model/src/channel/message/application.rs +++ b/model/src/channel/message/application.rs @@ -23,7 +23,7 @@ mod tests { cover_image: Some("cover".to_owned()), description: "a description".to_owned(), icon: Some("an icon".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "application".to_owned(), }; diff --git a/model/src/channel/message/mention.rs b/model/src/channel/message/mention.rs index d228f2070d5..c6c91c2d3de 100644 --- a/model/src/channel/message/mention.rs +++ b/model/src/channel/message/mention.rs @@ -58,7 +58,7 @@ mod tests { avatar: None, bot: false, discriminator: 1, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), member: None, name: "foo".to_owned(), public_flags: UserFlags::empty(), @@ -99,7 +99,7 @@ mod tests { avatar: None, bot: false, discriminator: 1, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), member: Some(PartialMember { avatar: None, communication_disabled_until: None, diff --git a/model/src/channel/message/mod.rs b/model/src/channel/message/mod.rs index e639640aa99..8f015c4d9aa 100644 --- a/model/src/channel/message/mod.rs +++ b/model/src/channel/message/mod.rs @@ -129,7 +129,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -138,14 +138,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -169,7 +169,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "sticker name".to_owned(), }], referenced_message: None, @@ -310,10 +310,10 @@ mod tests { cover_image: Some("cover".to_owned()), description: "a description".to_owned(), icon: Some("an icon".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "application".to_owned(), }), - application_id: Some(Id::new(1).expect("non zero")), + application_id: Some(Id::new_checked(1).expect("non zero")), attachments: Vec::new(), author: User { accent_color: None, @@ -323,7 +323,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -332,14 +332,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: Some(edited_timestamp), embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -355,8 +355,8 @@ mod tests { user: None, }), mention_channels: vec![ChannelMention { - guild_id: Id::new(1).expect("non zero"), - id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildText, name: "channel".to_owned(), }], @@ -372,21 +372,21 @@ mod tests { me: true, }], reference: Some(MessageReference { - channel_id: Some(Id::new(1).expect("non zero")), + channel_id: Some(Id::new_checked(1).expect("non zero")), guild_id: None, message_id: None, fail_if_not_exists: None, }), sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "sticker name".to_owned(), }], referenced_message: None, timestamp, thread: None, tts: false, - webhook_id: Some(Id::new(1).expect("non zero")), + webhook_id: Some(Id::new_checked(1).expect("non zero")), }; serde_test::assert_tokens( diff --git a/model/src/channel/message/reference.rs b/model/src/channel/message/reference.rs index 0b8ff8f76fb..b44434fb667 100644 --- a/model/src/channel/message/reference.rs +++ b/model/src/channel/message/reference.rs @@ -25,7 +25,7 @@ mod tests { #[test] fn test_minimal() { let value = MessageReference { - channel_id: Some(Id::new(1).expect("non zero")), + channel_id: Some(Id::new_checked(1).expect("non zero")), guild_id: None, message_id: None, fail_if_not_exists: None, @@ -50,9 +50,9 @@ mod tests { #[test] fn test_complete() { let value = MessageReference { - channel_id: Some(Id::new(1).expect("non zero")), - guild_id: Some(Id::new(2).expect("non zero")), - message_id: Some(Id::new(3).expect("non zero")), + channel_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), + message_id: Some(Id::new_checked(3).expect("non zero")), fail_if_not_exists: Some(false), }; diff --git a/model/src/channel/message/sticker/message.rs b/model/src/channel/message/sticker/message.rs index 22aabd99a91..ff0434ee7b4 100644 --- a/model/src/channel/message/sticker/message.rs +++ b/model/src/channel/message/sticker/message.rs @@ -37,7 +37,7 @@ mod tests { fn test_full() { let value = MessageSticker { format_type: StickerFormatType::Lottie, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "sticker".into(), }; diff --git a/model/src/channel/message/sticker/mod.rs b/model/src/channel/message/sticker/mod.rs index e6ae75b9035..539e0b854db 100644 --- a/model/src/channel/message/sticker/mod.rs +++ b/model/src/channel/message/sticker/mod.rs @@ -104,7 +104,7 @@ mod tests { description: Some("foo2".to_owned()), format_type: StickerFormatType::Png, guild_id: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: StickerType::Standard, name: "sticker name".to_owned(), pack_id: None, @@ -146,11 +146,11 @@ mod tests { available: true, description: Some("sticker".into()), format_type: StickerFormatType::Png, - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(2).expect("non zero"), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new(3).expect("non zero")), + pack_id: Some(Id::new_checked(3).expect("non zero")), sort_value: Some(1), tags: "foo,bar,baz".into(), user: Some(User { @@ -161,7 +161,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/channel/message/sticker/pack.rs b/model/src/channel/message/sticker/pack.rs index 866563e1278..d5e40228808 100644 --- a/model/src/channel/message/sticker/pack.rs +++ b/model/src/channel/message/sticker/pack.rs @@ -63,21 +63,21 @@ mod tests { #[test] fn test_full() { let value = StickerPack { - banner_asset_id: Some(Id::new(761_773_777_976_819_732).expect("non zero")), - cover_sticker_id: Some(Id::new(749_053_689_419_006_003).expect("non zero")), + banner_asset_id: Some(Id::new_checked(761_773_777_976_819_732).expect("non zero")), + cover_sticker_id: Some(Id::new_checked(749_053_689_419_006_003).expect("non zero")), description: "Say hello to Wumpus!".into(), - id: Id::new(847_199_849_233_514_549).expect("non zero"), + id: Id::new_checked(847_199_849_233_514_549).expect("non zero"), name: "Wumpus Beyond".into(), - sku_id: Id::new(847_199_849_233_514_547).expect("non zero"), + sku_id: Id::new_checked(847_199_849_233_514_547).expect("non zero"), stickers: Vec::from([Sticker { available: true, description: Some("Wumpus waves hello".into()), format_type: StickerFormatType::Lottie, guild_id: None, - id: Id::new(749_054_660_769_218_631).expect("non zero"), + id: Id::new_checked(749_054_660_769_218_631).expect("non zero"), kind: StickerType::Standard, name: "Wave".into(), - pack_id: Some(Id::new(847_199_849_233_514_549).expect("non zero")), + pack_id: Some(Id::new_checked(847_199_849_233_514_549).expect("non zero")), sort_value: Some(12), tags: "wumpus, hello, sup, hi, oi, heyo, heya, yo, wave".into(), user: None, diff --git a/model/src/channel/mod.rs b/model/src/channel/mod.rs index 8633db3668d..236a0e176ee 100644 --- a/model/src/channel/mod.rs +++ b/model/src/channel/mod.rs @@ -700,20 +700,20 @@ mod tests { Group { application_id: None, icon: None, - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), kind: ChannelType::Group, last_message_id: None, last_pin_timestamp: None, name: Some("a group".to_owned()), - owner_id: Id::new(456).expect("non zero"), + owner_id: Id::new_checked(456).expect("non zero"), recipients: Vec::new(), } } fn guild_category() -> CategoryChannel { CategoryChannel { - guild_id: Some(Id::new(321).expect("non zero")), - id: Id::new(123).expect("non zero"), + guild_id: Some(Id::new_checked(321).expect("non zero")), + id: Id::new_checked(123).expect("non zero"), kind: ChannelType::GuildCategory, name: "category".to_owned(), permission_overwrites: Vec::new(), @@ -723,8 +723,8 @@ mod tests { fn guild_text() -> TextChannel { TextChannel { - guild_id: Some(Id::new(321).expect("non zero")), - id: Id::new(456).expect("non zero"), + guild_id: Some(Id::new_checked(321).expect("non zero")), + id: Id::new_checked(456).expect("non zero"), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, @@ -741,8 +741,8 @@ mod tests { fn guild_voice() -> VoiceChannel { VoiceChannel { bitrate: 1000, - guild_id: Some(Id::new(321).expect("non zero")), - id: Id::new(789).expect("non zero"), + guild_id: Some(Id::new_checked(321).expect("non zero")), + id: Id::new_checked(789).expect("non zero"), kind: ChannelType::GuildVoice, name: "voice".to_owned(), permission_overwrites: Vec::new(), @@ -757,8 +757,8 @@ mod tests { fn guild_stage() -> VoiceChannel { VoiceChannel { bitrate: 1000, - guild_id: Some(Id::new(321).expect("non zero")), - id: Id::new(789).expect("non zero"), + guild_id: Some(Id::new_checked(321).expect("non zero")), + id: Id::new_checked(789).expect("non zero"), kind: ChannelType::GuildStageVoice, name: "stage".to_owned(), permission_overwrites: Vec::new(), @@ -772,7 +772,7 @@ mod tests { fn private() -> PrivateChannel { PrivateChannel { - id: Id::new(234).expect("non zero"), + id: Id::new_checked(234).expect("non zero"), last_message_id: None, last_pin_timestamp: None, kind: ChannelType::Private, @@ -784,27 +784,27 @@ mod tests { fn test_channel_helpers() { assert_eq!( Channel::Group(group()).id(), - Id::new(123).expect("non zero") + Id::new_checked(123).expect("non zero") ); assert_eq!( Channel::Guild(GuildChannel::Category(guild_category())).id(), - Id::new(123).expect("non zero") + Id::new_checked(123).expect("non zero") ); assert_eq!( Channel::Guild(GuildChannel::Text(guild_text())).id(), - Id::new(456).expect("non zero") + Id::new_checked(456).expect("non zero") ); assert_eq!( Channel::Guild(GuildChannel::Voice(guild_voice())).id(), - Id::new(789).expect("non zero") + Id::new_checked(789).expect("non zero") ); assert_eq!( Channel::Guild(GuildChannel::Stage(guild_stage())).id(), - Id::new(789).expect("non zero") + Id::new_checked(789).expect("non zero") ); assert_eq!( Channel::Private(private()).id(), - Id::new(234).expect("non zero") + Id::new_checked(234).expect("non zero") ); } @@ -879,19 +879,19 @@ mod tests { fn test_guild_channel_guild_id() { assert_eq!( GuildChannel::Category(guild_category()).guild_id(), - Some(Id::new(321).expect("non zero")) + Some(Id::new_checked(321).expect("non zero")) ); assert_eq!( GuildChannel::Text(guild_text()).guild_id(), - Some(Id::new(321).expect("non zero")) + Some(Id::new_checked(321).expect("non zero")) ); assert_eq!( GuildChannel::Voice(guild_voice()).guild_id(), - Some(Id::new(321).expect("non zero")) + Some(Id::new_checked(321).expect("non zero")) ); assert_eq!( GuildChannel::Stage(guild_stage()).guild_id(), - Some(Id::new(321).expect("non zero")) + Some(Id::new_checked(321).expect("non zero")) ); } @@ -899,19 +899,19 @@ mod tests { fn test_guild_channel_id() { assert_eq!( GuildChannel::Category(guild_category()).id(), - Id::new(123).expect("non zero") + Id::new_checked(123).expect("non zero") ); assert_eq!( GuildChannel::Text(guild_text()).id(), - Id::new(456).expect("non zero") + Id::new_checked(456).expect("non zero") ); assert_eq!( GuildChannel::Voice(guild_voice()).id(), - Id::new(789).expect("non zero") + Id::new_checked(789).expect("non zero") ); assert_eq!( GuildChannel::Stage(guild_stage()).id(), - Id::new(789).expect("non zero") + Id::new_checked(789).expect("non zero") ); } @@ -955,10 +955,10 @@ mod tests { }); let value = GuildChannel::Text(TextChannel { - guild_id: Some(Id::new(1).expect("non zero")), - id: Id::new(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildText, - last_message_id: Some(Id::new(3).expect("non zero")), + last_message_id: Some(Id::new_checked(3).expect("non zero")), last_pin_timestamp: None, name: "hey".to_owned(), nsfw: false, @@ -975,8 +975,8 @@ mod tests { #[test] fn test_guild_category_channel_deserialization() { let value = GuildChannel::Category(CategoryChannel { - id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildCategory, name: "foo".to_owned(), permission_overwrites: Vec::new(), @@ -1003,15 +1003,15 @@ mod tests { #[test] fn test_guild_news_channel_deserialization() { let value = GuildChannel::Text(TextChannel { - id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildNews, - last_message_id: Some(Id::new(4).expect("non zero")), + last_message_id: Some(Id::new_checked(4).expect("non zero")), last_pin_timestamp: None, name: "news".to_owned(), nsfw: true, permission_overwrites: Vec::new(), - parent_id: Some(Id::new(5).expect("non zero")), + parent_id: Some(Id::new_checked(5).expect("non zero")), position: 3, rate_limit_per_user: None, topic: Some("a news channel".to_owned()), @@ -1039,8 +1039,8 @@ mod tests { #[test] fn test_guild_store_channel_deserialization() { let value = GuildChannel::Text(TextChannel { - id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildStore, last_message_id: None, last_pin_timestamp: None, @@ -1077,23 +1077,23 @@ mod tests { let value = GuildChannel::NewsThread(NewsThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(1)).expect("non zero"), - id: Id::new(6).expect("non zero"), + guild_id: Some(Id::new_checked(1)).expect("non zero"), + id: Id::new_checked(6).expect("non zero"), kind: ChannelType::GuildNewsThread, - last_message_id: Some(Id::new(3)).expect("non zero"), + last_message_id: Some(Id::new_checked(3)).expect("non zero"), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new(4)).expect("non zero"), + id: Some(Id::new_checked(4)).expect("non zero"), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(5)).expect("non zero"), + user_id: Some(Id::new_checked(5)).expect("non zero"), }), member_count: 50_u8, message_count: 50_u8, name: "newsthread".into(), - owner_id: Some(Id::new(5)).expect("non zero"), - parent_id: Some(Id::new(2)).expect("non zero"), + owner_id: Some(Id::new_checked(5)).expect("non zero"), + parent_id: Some(Id::new_checked(2)).expect("non zero"), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { archived: false, @@ -1141,23 +1141,23 @@ mod tests { let value = GuildChannel::PublicThread(PublicThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(1)).expect("non zero"), - id: Id::new(6).expect("non zero"), + guild_id: Some(Id::new_checked(1)).expect("non zero"), + id: Id::new_checked(6).expect("non zero"), kind: ChannelType::GuildPublicThread, - last_message_id: Some(Id::new(3)).expect("non zero"), + last_message_id: Some(Id::new_checked(3)).expect("non zero"), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new(4)).expect("non zero"), + id: Some(Id::new_checked(4)).expect("non zero"), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(5)).expect("non zero"), + user_id: Some(Id::new_checked(5)).expect("non zero"), }), member_count: 50_u8, message_count: 50_u8, name: "publicthread".into(), - owner_id: Some(Id::new(5)).expect("non zero"), - parent_id: Some(Id::new(2)).expect("non zero"), + owner_id: Some(Id::new_checked(5)).expect("non zero"), + parent_id: Some(Id::new_checked(2)).expect("non zero"), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { archived: false, @@ -1206,28 +1206,28 @@ mod tests { let value = GuildChannel::PrivateThread(PrivateThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(1)).expect("non zero"), - id: Id::new(6).expect("non zero"), + guild_id: Some(Id::new_checked(1)).expect("non zero"), + id: Id::new_checked(6).expect("non zero"), invitable: Some(true), kind: ChannelType::GuildPrivateThread, - last_message_id: Some(Id::new(3)).expect("non zero"), + last_message_id: Some(Id::new_checked(3)).expect("non zero"), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new(4)).expect("non zero"), + id: Some(Id::new_checked(4)).expect("non zero"), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(5)).expect("non zero"), + user_id: Some(Id::new_checked(5)).expect("non zero"), }), member_count: 50_u8, message_count: 50_u8, name: "privatethread".into(), - owner_id: Some(Id::new(5)).expect("non zero"), - parent_id: Some(Id::new(2)).expect("non zero"), + owner_id: Some(Id::new_checked(5)).expect("non zero"), + parent_id: Some(Id::new_checked(2)).expect("non zero"), permission_overwrites: Vec::from([PermissionOverwrite { allow: Permissions::empty(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Member(Id::new(5).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new_checked(5).expect("non zero")), }]), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { diff --git a/model/src/channel/permission_overwrite.rs b/model/src/channel/permission_overwrite.rs index e3e984e117b..3f3abdd2da3 100644 --- a/model/src/channel/permission_overwrite.rs +++ b/model/src/channel/permission_overwrite.rs @@ -83,14 +83,14 @@ impl<'de> Deserialize<'de> for PermissionOverwrite { let kind = match data.kind { PermissionOverwriteTargetType::Member => { - let id = Id::new(data.id).expect("non zero"); + let id = Id::new_checked(data.id).expect("non zero"); #[cfg(feature = "tracing")] tracing::trace!(id = %id.get(), kind = ?data.kind); PermissionOverwriteType::Member(id) } PermissionOverwriteTargetType::Role => { - let id = Id::new(data.id).expect("non zero"); + let id = Id::new_checked(data.id).expect("non zero"); #[cfg(feature = "tracing")] tracing::trace!(id = %id.get(), kind = ?data.kind); @@ -180,7 +180,7 @@ mod tests { let overwrite = PermissionOverwrite { allow: Permissions::CREATE_INVITE, deny: Permissions::KICK_MEMBERS, - kind: PermissionOverwriteType::Member(Id::new(12_345_678).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new_checked(12_345_678).expect("non zero")), }; // We can't use serde_test because it doesn't support 128 bit integers. @@ -213,7 +213,7 @@ mod tests { let value = PermissionOverwrite { allow: Permissions::CREATE_INVITE, deny: Permissions::KICK_MEMBERS, - kind: PermissionOverwriteType::Member(Id::new(1).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new_checked(1).expect("non zero")), }; let deserialized = serde_json::from_str::(raw).unwrap(); diff --git a/model/src/channel/private_channel.rs b/model/src/channel/private_channel.rs index 1d4bee290a9..220234ecbd3 100644 --- a/model/src/channel/private_channel.rs +++ b/model/src/channel/private_channel.rs @@ -36,8 +36,8 @@ mod tests { let last_pin_timestamp = Timestamp::from_str("2021-08-10T12:34:00+00:00")?; let value = PrivateChannel { - id: Id::new(1).expect("non zero"), - last_message_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + last_message_id: Some(Id::new_checked(2).expect("non zero")), last_pin_timestamp: Some(last_pin_timestamp), kind: ChannelType::Private, recipients: Vec::new(), diff --git a/model/src/channel/reaction.rs b/model/src/channel/reaction.rs index 9823baae2ed..c0d7b542bdd 100644 --- a/model/src/channel/reaction.rs +++ b/model/src/channel/reaction.rs @@ -115,7 +115,7 @@ impl<'de> Visitor<'de> for ReactionVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); member = map.next_value_seed(deserializer)?; } @@ -195,22 +195,22 @@ mod tests { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = Reaction { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "a".to_owned(), }, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(5).expect("non zero")], + roles: vec![Id::new_checked(5).expect("non zero")], user: User { accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), @@ -219,7 +219,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(4).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -229,8 +229,8 @@ mod tests { verified: None, }, }), - message_id: Id::new(3).expect("non zero"), - user_id: Id::new(4).expect("non zero"), + message_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new_checked(4).expect("non zero"), }; serde_test::assert_tokens( @@ -321,14 +321,14 @@ mod tests { #[test] fn test_reaction_without_member() { let value = Reaction { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "a".to_owned(), }, guild_id: None, member: None, - message_id: Id::new(3).expect("non zero"), - user_id: Id::new(4).expect("non zero"), + message_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new_checked(4).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/channel/reaction_type.rs b/model/src/channel/reaction_type.rs index 89b78caf00b..cc056c79b12 100644 --- a/model/src/channel/reaction_type.rs +++ b/model/src/channel/reaction_type.rs @@ -31,7 +31,7 @@ mod tests { fn test_custom() { let value = ReactionType::Custom { animated: false, - id: Id::new(1337).expect("non zero"), + id: Id::new_checked(1337).expect("non zero"), name: Some("foo".to_owned()), }; diff --git a/model/src/channel/stage_instance/mod.rs b/model/src/channel/stage_instance/mod.rs index aba4ad5893b..cf6b0a85547 100644 --- a/model/src/channel/stage_instance/mod.rs +++ b/model/src/channel/stage_instance/mod.rs @@ -27,10 +27,10 @@ mod test { #[test] fn test_stage_instance() { let value = StageInstance { - channel_id: Id::new(100).expect("non zero"), + channel_id: Id::new_checked(100).expect("non zero"), discoverable_disabled: false, - guild_id: Id::new(200).expect("non zero"), - id: Id::new(300).expect("non zero"), + guild_id: Id::new_checked(200).expect("non zero"), + id: Id::new_checked(300).expect("non zero"), privacy_level: PrivacyLevel::Public, topic: "a topic".into(), }; diff --git a/model/src/channel/text_channel.rs b/model/src/channel/text_channel.rs index b5046ccdfdf..5964f12d060 100644 --- a/model/src/channel/text_channel.rs +++ b/model/src/channel/text_channel.rs @@ -45,8 +45,8 @@ mod tests { #[test] fn test_text_channel() { let value = TextChannel { - id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, @@ -100,15 +100,15 @@ mod tests { let last_pin_timestamp = Timestamp::from_str("2021-08-10T12:34:00+00:00")?; let value = TextChannel { - id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildText, - last_message_id: Some(Id::new(3).expect("non zero")), + last_message_id: Some(Id::new_checked(3).expect("non zero")), last_pin_timestamp: Some(last_pin_timestamp), name: "foo".to_owned(), nsfw: true, permission_overwrites: Vec::new(), - parent_id: Some(Id::new(4).expect("non zero")), + parent_id: Some(Id::new_checked(4).expect("non zero")), position: 3, rate_limit_per_user: Some(10), topic: Some("a topic".to_owned()), diff --git a/model/src/channel/thread/member.rs b/model/src/channel/thread/member.rs index 31a7cfaa236..d26d441b3d1 100644 --- a/model/src/channel/thread/member.rs +++ b/model/src/channel/thread/member.rs @@ -75,11 +75,11 @@ mod tests { let value = ThreadMember { flags: 3, - id: Some(Id::new(1).expect("non zero")), + id: Some(Id::new_checked(1).expect("non zero")), member: None, presence: None, join_timestamp, - user_id: Some(Id::new(2).expect("non zero")), + user_id: Some(Id::new_checked(2).expect("non zero")), }; serde_test::assert_tokens( diff --git a/model/src/channel/thread/news.rs b/model/src/channel/thread/news.rs index a9a7d9c3064..0383240533d 100644 --- a/model/src/channel/thread/news.rs +++ b/model/src/channel/thread/news.rs @@ -55,23 +55,23 @@ mod tests { let value = NewsThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(2).expect("non zero")), - id: Id::new(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildNewsThread, - last_message_id: Some(Id::new(5).expect("non zero")), + last_message_id: Some(Id::new_checked(5).expect("non zero")), member: Some(ThreadMember { flags: 12, - id: Some(Id::new(10).expect("non zero")), + id: Some(Id::new_checked(10).expect("non zero")), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(11).expect("non zero")), + user_id: Some(Id::new_checked(11).expect("non zero")), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new(3).expect("non zero")), - parent_id: Some(Id::new(4).expect("non zero")), + owner_id: Some(Id::new_checked(3).expect("non zero")), + parent_id: Some(Id::new_checked(4).expect("non zero")), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { archived: true, diff --git a/model/src/channel/thread/private.rs b/model/src/channel/thread/private.rs index abcc02cd0e6..63a08a819b5 100644 --- a/model/src/channel/thread/private.rs +++ b/model/src/channel/thread/private.rs @@ -63,24 +63,24 @@ mod tests { let value = PrivateThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(2).expect("non zero")), - id: Id::new(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), invitable: Some(true), kind: ChannelType::GuildPrivateThread, - last_message_id: Some(Id::new(5).expect("non zero")), + last_message_id: Some(Id::new_checked(5).expect("non zero")), member: Some(ThreadMember { flags: 12, - id: Some(Id::new(10)).expect("non zero"), + id: Some(Id::new_checked(10)).expect("non zero"), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(11)).expect("non zero"), + user_id: Some(Id::new_checked(11)).expect("non zero"), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new(3).expect("non zero")), - parent_id: Some(Id::new(4).expect("non zero")), + owner_id: Some(Id::new_checked(3).expect("non zero")), + parent_id: Some(Id::new_checked(4).expect("non zero")), permission_overwrites: Vec::new(), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { diff --git a/model/src/channel/thread/public.rs b/model/src/channel/thread/public.rs index c5f05af3769..9dbdaac7593 100644 --- a/model/src/channel/thread/public.rs +++ b/model/src/channel/thread/public.rs @@ -56,23 +56,23 @@ mod tests { let value = PublicThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new(2).expect("non zero")), - id: Id::new(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildPublicThread, - last_message_id: Some(Id::new(5).expect("non zero")), + last_message_id: Some(Id::new_checked(5).expect("non zero")), member: Some(ThreadMember { flags: 12, - id: Some(Id::new(10).expect("non zero")), + id: Some(Id::new_checked(10).expect("non zero")), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new(11).expect("non zero")), + user_id: Some(Id::new_checked(11).expect("non zero")), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new(3).expect("non zero")), - parent_id: Some(Id::new(4).expect("non zero")), + owner_id: Some(Id::new_checked(3).expect("non zero")), + parent_id: Some(Id::new_checked(4).expect("non zero")), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { archived: true, diff --git a/model/src/channel/voice_channel.rs b/model/src/channel/voice_channel.rs index 0270bea982c..ba8e18d6280 100644 --- a/model/src/channel/voice_channel.rs +++ b/model/src/channel/voice_channel.rs @@ -40,9 +40,9 @@ mod tests { #[test] fn test_voice_channel() { let value = VoiceChannel { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), bitrate: 124_000, - guild_id: Some(Id::new(2).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind: ChannelType::GuildVoice, name: "foo".to_owned(), permission_overwrites: Vec::new(), @@ -90,13 +90,13 @@ mod tests { fn test_voice_channel_complete() { fn channel(kind: ChannelType) -> VoiceChannel { VoiceChannel { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), bitrate: 124_000, - guild_id: Some(Id::new(2).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), kind, name: "foo".to_owned(), permission_overwrites: Vec::new(), - parent_id: Some(Id::new(3).expect("non zero")), + parent_id: Some(Id::new_checked(3).expect("non zero")), position: 3, rtc_region: Some("a".to_owned()), user_limit: Some(7), diff --git a/model/src/channel/webhook/mod.rs b/model/src/channel/webhook/mod.rs index f325e68263e..e45fe4eab9b 100644 --- a/model/src/channel/webhook/mod.rs +++ b/model/src/channel/webhook/mod.rs @@ -80,11 +80,11 @@ mod tests { #[test] fn test_webhook() { let value = Webhook { - application_id: Some(Id::new(4).expect("non zero")), + application_id: Some(Id::new_checked(4).expect("non zero")), avatar: Some("avatar".to_owned()), - channel_id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), - id: Id::new(3).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new_checked(3).expect("non zero"), kind: WebhookType::Incoming, name: Some("a webhook".to_owned()), source_channel: None, @@ -135,20 +135,20 @@ mod tests { #[test] fn test_webhook_complete() { let value = Webhook { - application_id: Some(Id::new(4).expect("non zero")), + application_id: Some(Id::new_checked(4).expect("non zero")), avatar: Some("avatar".to_owned()), - channel_id: Id::new(1).expect("non zero"), - guild_id: Some(Id::new(2).expect("non zero")), - id: Id::new(3).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new_checked(3).expect("non zero"), kind: WebhookType::Incoming, name: Some("a webhook".to_owned()), source_channel: Some(WebhookChannel { - id: Id::new(4).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), name: "webhook channel".into(), }), source_guild: Some(WebhookGuild { icon: Some("guild icon".into()), - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), name: "webhook guild".into(), }), token: Some("a token".to_owned()), @@ -161,7 +161,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/gateway/event/gateway.rs b/model/src/gateway/event/gateway.rs index a4f42c09b22..4b9701d82b1 100644 --- a/model/src/gateway/event/gateway.rs +++ b/model/src/gateway/event/gateway.rs @@ -852,8 +852,8 @@ mod tests { #[test] fn test_serialize_dispatch() { let role_delete = RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), }; let dispatch = Box::new(DispatchEvent::RoleDelete(role_delete)); let value = GatewayEvent::Dispatch(2_048, dispatch); diff --git a/model/src/gateway/payload/incoming/guild_delete.rs b/model/src/gateway/payload/incoming/guild_delete.rs index 8495ad5303b..37f9b6ac798 100644 --- a/model/src/gateway/payload/incoming/guild_delete.rs +++ b/model/src/gateway/payload/incoming/guild_delete.rs @@ -23,7 +23,7 @@ mod tests { #[test] fn test_guild_delete_available() { let expected = GuildDelete { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), unavailable: true, }; @@ -62,7 +62,7 @@ mod tests { #[test] fn test_guild_delete_unavailable() { let expected = GuildDelete { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), unavailable: false, }; @@ -101,7 +101,7 @@ mod tests { #[test] fn test_guild_delete_unavailable_null_default() { let expected = GuildDelete { - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), unavailable: false, }; diff --git a/model/src/gateway/payload/incoming/invite_create.rs b/model/src/gateway/payload/incoming/invite_create.rs index 09380fba983..c1651da540a 100644 --- a/model/src/gateway/payload/incoming/invite_create.rs +++ b/model/src/gateway/payload/incoming/invite_create.rs @@ -133,10 +133,10 @@ mod tests { let created_at = Timestamp::from_secs(1_609_459_200).expect("non zero"); let value = InviteCreate { - channel_id: Id::new(1).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), code: "a".repeat(7), created_at, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), inviter: None, max_age: 3600, max_uses: 5, @@ -181,7 +181,7 @@ mod tests { let value = PartialUser { avatar: Some("a".repeat(32)), discriminator: 123, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), username: "twilight".to_owned(), }; diff --git a/model/src/gateway/payload/incoming/member_add.rs b/model/src/gateway/payload/incoming/member_add.rs index fe9778492f5..f512e58300d 100644 --- a/model/src/gateway/payload/incoming/member_add.rs +++ b/model/src/gateway/payload/incoming/member_add.rs @@ -33,7 +33,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: None, @@ -41,7 +41,7 @@ mod tests { premium_since: None, roles: vec![], user: User { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), accent_color: None, avatar: None, banner: None, diff --git a/model/src/gateway/payload/incoming/member_chunk.rs b/model/src/gateway/payload/incoming/member_chunk.rs index 9a20a9b81ea..00e363c458e 100644 --- a/model/src/gateway/payload/incoming/member_chunk.rs +++ b/model/src/gateway/payload/incoming/member_chunk.rs @@ -123,7 +123,8 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { // Since the guild ID may not be deserialized yet we'll use // a temporary placeholder value and update it with the real // guild ID after all the fields have been deserialized. - let deserializer = MemberListDeserializer::new(Id::new(1).expect("non zero")); + let deserializer = + MemberListDeserializer::new(Id::new_checked(1).expect("non zero")); members = Some(map.next_value_seed(deserializer)?); } @@ -146,7 +147,8 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { return Err(DeError::duplicate_field("presences")); } - let deserializer = PresenceListDeserializer::new(Id::new(1).expect("non zero")); + let deserializer = + PresenceListDeserializer::new(Id::new_checked(1).expect("non zero")); presences = Some(map.next_value_seed(deserializer)?); } @@ -327,21 +329,24 @@ mod tests { let expected = MemberChunk { chunk_count: 1, chunk_index: 0, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), members: Vec::from([ Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6).expect("non zero"), Id::new(7).expect("non zero")], + roles: vec![ + Id::new_checked(6).expect("non zero"), + Id::new_checked(7).expect("non zero"), + ], user: User { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), accent_color: None, avatar: Some("dddddddddddddddddddddddddddddddd".to_owned()), banner: None, @@ -362,15 +367,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6).expect("non zero")], + roles: vec![Id::new_checked(6).expect("non zero")], user: User { - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), accent_color: None, avatar: Some("cccccccccccccccccccccccccccccccc".to_owned()), banner: None, @@ -391,15 +396,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: true, premium_since: None, - roles: vec![Id::new(6).expect("non zero")], + roles: vec![Id::new_checked(6).expect("non zero")], user: User { - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), banner: None, @@ -420,15 +425,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6).expect("non zero")], + roles: vec![Id::new_checked(6).expect("non zero")], user: User { - id: Id::new(6).expect("non zero"), + id: Id::new_checked(6).expect("non zero"), accent_color: None, avatar: Some("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".to_owned()), banner: None, @@ -456,10 +461,10 @@ mod tests { mobile: None, web: Some(Status::Online), }, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), status: Status::Online, user: UserOrId::UserId { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), }, }, Presence { @@ -469,10 +474,10 @@ mod tests { mobile: None, web: Some(Status::Online), }, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), status: Status::Online, user: UserOrId::UserId { - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), }, }, Presence { @@ -482,10 +487,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), status: Status::DoNotDisturb, user: UserOrId::UserId { - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), }, }, ]), diff --git a/model/src/gateway/payload/incoming/member_update.rs b/model/src/gateway/payload/incoming/member_update.rs index 26be0077eef..e6653fb5a7e 100644 --- a/model/src/gateway/payload/incoming/member_update.rs +++ b/model/src/gateway/payload/incoming/member_update.rs @@ -45,7 +45,7 @@ mod tests { let value = MemberUpdate { avatar: None, - guild_id: Id::new(1_234).expect("non zero"), + guild_id: Id::new_checked(1_234).expect("non zero"), deaf: Some(false), joined_at, @@ -59,7 +59,7 @@ mod tests { banner: None, name: "Twilight Sparkle".to_string(), public_flags: None, - id: Id::new(424_242).expect("non zero"), + id: Id::new_checked(424_242).expect("non zero"), discriminator: 1234, avatar: Some("cool image".to_string()), bot: false, diff --git a/model/src/gateway/payload/incoming/ready.rs b/model/src/gateway/payload/incoming/ready.rs index 54223e0d7d9..031e50c6f78 100644 --- a/model/src/gateway/payload/incoming/ready.rs +++ b/model/src/gateway/payload/incoming/ready.rs @@ -29,11 +29,11 @@ mod tests { fn test_ready() { let guilds = vec![ UnavailableGuild { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), unavailable: true, }, UnavailableGuild { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), unavailable: true, }, ]; @@ -41,7 +41,7 @@ mod tests { let ready = Ready { application: PartialApplication { flags: ApplicationFlags::empty(), - id: Id::new(100).expect("non zero"), + id: Id::new_checked(100).expect("non zero"), }, guilds, session_id: "foo".to_owned(), @@ -54,7 +54,7 @@ mod tests { discriminator: 1212, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: false, name: "bar".to_owned(), diff --git a/model/src/gateway/payload/incoming/role_delete.rs b/model/src/gateway/payload/incoming/role_delete.rs index 09e36304ac6..2a516615171 100644 --- a/model/src/gateway/payload/incoming/role_delete.rs +++ b/model/src/gateway/payload/incoming/role_delete.rs @@ -19,8 +19,8 @@ mod tests { #[test] fn test_webhooks_update() { let value = RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/role_update.rs b/model/src/gateway/payload/incoming/role_update.rs index 6c5cc7270b3..384e85ccb76 100644 --- a/model/src/gateway/payload/incoming/role_update.rs +++ b/model/src/gateway/payload/incoming/role_update.rs @@ -19,12 +19,12 @@ mod tests { #[test] fn test_role_update() { let value = RoleUpdate { - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), role: Role { color: 0, hoist: true, icon: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), managed: false, mentionable: false, name: "a role".to_owned(), diff --git a/model/src/gateway/payload/incoming/thread_members_update.rs b/model/src/gateway/payload/incoming/thread_members_update.rs index 1328d8e8e65..7848e2117b4 100644 --- a/model/src/gateway/payload/incoming/thread_members_update.rs +++ b/model/src/gateway/payload/incoming/thread_members_update.rs @@ -112,7 +112,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: None, deaf: false, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -127,7 +127,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -167,10 +167,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), status: Status::Online, user: UserOrId::UserId { - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), }, }; @@ -179,14 +179,14 @@ mod tests { let value = ThreadMembersUpdate { added_members: vec![ThreadMember { flags: 1, - id: Some(Id::new(123).expect("non zero")), + id: Some(Id::new_checked(123).expect("non zero")), join_timestamp, member: Some(member), presence: Some(presence), - user_id: Some(Id::new(3).expect("non zero")), + user_id: Some(Id::new_checked(3).expect("non zero")), }], - guild_id: Id::new(2).expect("non zero"), - id: Id::new(4).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), member_count: 8, removed_member_ids: vec![], }; diff --git a/model/src/gateway/payload/incoming/typing_start.rs b/model/src/gateway/payload/incoming/typing_start.rs index 41edfd1e1e5..7d75bf2fd30 100644 --- a/model/src/gateway/payload/incoming/typing_start.rs +++ b/model/src/gateway/payload/incoming/typing_start.rs @@ -106,7 +106,7 @@ impl<'de> Visitor<'de> for TypingStartVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); member = map.next_value_seed(deserializer)?; } @@ -183,21 +183,21 @@ mod tests { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = TypingStart { - channel_id: Id::new(2).expect("non zero"), - guild_id: Some(Id::new(1).expect("non zero")), + channel_id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(4).expect("non zero")], + roles: vec![Id::new_checked(4).expect("non zero")], user: User { - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), banner: None, @@ -215,7 +215,7 @@ mod tests { }, }), timestamp: 1_500_000_000, - user_id: Id::new(3).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), }; serde_test::assert_tokens( @@ -297,11 +297,11 @@ mod tests { #[test] fn test_typing_start_without_member() { let value = TypingStart { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), guild_id: None, member: None, timestamp: 1_500_000_000, - user_id: Id::new(3).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/unavailable_guild.rs b/model/src/gateway/payload/incoming/unavailable_guild.rs index eed0dafcdb1..202a99588a1 100644 --- a/model/src/gateway/payload/incoming/unavailable_guild.rs +++ b/model/src/gateway/payload/incoming/unavailable_guild.rs @@ -15,7 +15,7 @@ mod tests { #[test] fn test_unavailable_guild() { let value = UnavailableGuild { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/voice_state_update.rs b/model/src/gateway/payload/incoming/voice_state_update.rs index fa05d408a74..398f79faa91 100644 --- a/model/src/gateway/payload/incoming/voice_state_update.rs +++ b/model/src/gateway/payload/incoming/voice_state_update.rs @@ -24,20 +24,20 @@ mod tests { let value = VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: false, nick: None, pending: false, premium_since: None, - roles: vec![Id::new(4).expect("non zero")], + roles: vec![Id::new_checked(4).expect("non zero")], user: User { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), accent_color: None, avatar: None, banner: None, @@ -61,7 +61,7 @@ mod tests { session_id: "a".to_owned(), suppress: false, token: None, - user_id: Id::new(1).expect("non zero"), + user_id: Id::new_checked(1).expect("non zero"), request_to_speak_timestamp: None, }); @@ -162,23 +162,23 @@ mod tests { let value = VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new(999_999).expect("non zero")), + guild_id: Some(Id::new_checked(999_999).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(999_999).expect("non zero"), + guild_id: Id::new_checked(999_999).expect("non zero"), joined_at, mute: false, nick: Some("Twilight".to_string()), pending: false, premium_since: None, roles: vec![ - Id::new(123).expect("non zero"), - Id::new(124).expect("non zero"), + Id::new_checked(123).expect("non zero"), + Id::new_checked(124).expect("non zero"), ], user: User { - id: Id::new(1_234_123_123_123).expect("non zero"), + id: Id::new_checked(1_234_123_123_123).expect("non zero"), accent_color: None, avatar: Some("a21312321231236060dfe562c".to_string()), banner: None, @@ -202,7 +202,7 @@ mod tests { session_id: "asdasdas1da98da2b3ab3a".to_owned(), suppress: false, token: None, - user_id: Id::new(123_213).expect("non zero"), + user_id: Id::new_checked(123_213).expect("non zero"), request_to_speak_timestamp: Some(request_to_speak_timestamp), }); diff --git a/model/src/gateway/payload/incoming/webhooks_update.rs b/model/src/gateway/payload/incoming/webhooks_update.rs index 901387aee05..79e67453a45 100644 --- a/model/src/gateway/payload/incoming/webhooks_update.rs +++ b/model/src/gateway/payload/incoming/webhooks_update.rs @@ -19,8 +19,8 @@ mod tests { #[test] fn test_webhooks_update() { let value = WebhooksUpdate { - channel_id: Id::new(1).expect("non zero"), - guild_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/outgoing/request_guild_members.rs b/model/src/gateway/payload/outgoing/request_guild_members.rs index fe48bcfa512..04525330949 100644 --- a/model/src/gateway/payload/outgoing/request_guild_members.rs +++ b/model/src/gateway/payload/outgoing/request_guild_members.rs @@ -144,11 +144,11 @@ impl RequestGuildMembersBuilder { /// ``` /// use twilight_model::{gateway::payload::outgoing::RequestGuildMembers, id::Id}; /// - /// let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) /// .presences(true) /// .query("a", None); /// - /// assert_eq!(Id::new(1).expect("non zero"), request.d.guild_id); + /// assert_eq!(Id::new_checked(1).expect("non zero"), request.d.guild_id); /// assert_eq!(Some(0), request.d.limit); /// assert_eq!(Some("a"), request.d.query.as_deref()); /// assert_eq!(Some(true), request.d.presences); @@ -187,11 +187,11 @@ impl RequestGuildMembersBuilder { /// id::Id, /// }; /// - /// let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) /// .nonce("test") - /// .user_id(Id::new(2).expect("non zero")); + /// .user_id(Id::new_checked(2).expect("non zero")); /// - /// assert_eq!(Some(RequestGuildMemberId::One(Id::new(2).expect("non zero"))), request.d.user_ids); + /// assert_eq!(Some(RequestGuildMemberId::One(Id::new_checked(2).expect("non zero"))), request.d.user_ids); /// ``` #[allow(clippy::missing_const_for_fn)] pub fn user_id(self, user_id: Id) -> RequestGuildMembers { @@ -227,9 +227,9 @@ impl RequestGuildMembersBuilder { /// }; /// /// # fn main() -> Result<(), Box> { - /// let request = RequestGuildMembers::builder(Id::new(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) /// .nonce("test") - /// .user_ids(vec![Id::new(2).expect("non zero"), Id::new(2).expect("non zero")])?; + /// .user_ids(vec![Id::new_checked(2).expect("non zero"), Id::new_checked(2).expect("non zero")])?; /// /// assert!(matches!(request.d.user_ids, Some(RequestGuildMemberId::Multiple(ids)) if ids.len() == 2)); /// # Ok(()) } diff --git a/model/src/gateway/presence/mod.rs b/model/src/gateway/presence/mod.rs index f97aeff04fa..259fcb33a4b 100644 --- a/model/src/gateway/presence/mod.rs +++ b/model/src/gateway/presence/mod.rs @@ -210,10 +210,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), status: Status::Online, user: UserOrId::UserId { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), }, }; @@ -314,15 +314,15 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), status: Status::Online, user: UserOrId::UserId { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), }, }]); let mut json_deserializer = Deserializer::from_str(input); - let deserializer = PresenceListDeserializer::new(Id::new(2).expect("non zero")); + let deserializer = PresenceListDeserializer::new(Id::new_checked(2).expect("non zero")); let actual = deserializer.deserialize(&mut json_deserializer).unwrap(); assert_eq!(actual, expected); diff --git a/model/src/guild/audit_log/change.rs b/model/src/guild/audit_log/change.rs index 5bfd2824a0c..d66898f01cd 100644 --- a/model/src/guild/audit_log/change.rs +++ b/model/src/guild/audit_log/change.rs @@ -856,7 +856,7 @@ mod tests { #[test] fn test_afk_channel_id() { let value = AuditLogChange::AfkChannelId { - new: Some(Id::new(1).expect("non zero")), + new: Some(Id::new_checked(1).expect("non zero")), old: None, }; diff --git a/model/src/guild/audit_log/entry.rs b/model/src/guild/audit_log/entry.rs index 7ab229c3b24..4396219b65c 100644 --- a/model/src/guild/audit_log/entry.rs +++ b/model/src/guild/audit_log/entry.rs @@ -76,11 +76,11 @@ mod tests { new: None, old: Some(OLD.to_owned()), }]), - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), options: None, reason: Some("some reason".to_owned()), - target_id: Some(Id::new(2).expect("non zero")), - user_id: Some(Id::new(1).expect("non zero")), + target_id: Some(Id::new_checked(2).expect("non zero")), + user_id: Some(Id::new_checked(1).expect("non zero")), }; serde_test::assert_tokens( diff --git a/model/src/guild/ban.rs b/model/src/guild/ban.rs index 9fd9c69d180..ff93b358210 100644 --- a/model/src/guild/ban.rs +++ b/model/src/guild/ban.rs @@ -25,7 +25,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(100_000_000_000_000_000).expect("non zero"), + id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/guild/emoji.rs b/model/src/guild/emoji.rs index 404dc72ed6d..b59624b8b6e 100644 --- a/model/src/guild/emoji.rs +++ b/model/src/guild/emoji.rs @@ -40,7 +40,7 @@ mod tests { let emoji = Emoji { animated: false, available: true, - id: Id::new(100_000_000_000_000_000).expect("non zero"), + id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), managed: false, name: "test".to_owned(), require_colons: true, @@ -53,7 +53,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -116,11 +116,11 @@ mod tests { let emoji = Emoji { animated: false, available: true, - id: Id::new(100_000_000_000_000_000).expect("non zero"), + id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), managed: false, name: "test".to_owned(), require_colons: true, - roles: vec![Id::new(1).expect("non zero")], + roles: vec![Id::new_checked(1).expect("non zero")], user: Some(User { accent_color: None, avatar: None, @@ -129,7 +129,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/guild/info.rs b/model/src/guild/info.rs index 6dbf79ad295..752faa6a904 100644 --- a/model/src/guild/info.rs +++ b/model/src/guild/info.rs @@ -23,7 +23,7 @@ mod tests { fn test_guild_info() { let value = GuildInfo { icon: Some("icon hash".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "guild name".to_owned(), owner: false, permissions: Permissions::MANAGE_CHANNELS, diff --git a/model/src/guild/integration.rs b/model/src/guild/integration.rs index 5f7f3d681a9..708ccb78299 100644 --- a/model/src/guild/integration.rs +++ b/model/src/guild/integration.rs @@ -70,11 +70,11 @@ mod tests { expire_behavior: Some(IntegrationExpireBehavior::Kick), expire_grace_period: Some(3_600), guild_id: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: "a".to_owned(), name: "integration name".to_owned(), revoked: Some(false), - role_id: Some(Id::new(3).expect("non zero")), + role_id: Some(Id::new_checked(3).expect("non zero")), subscriber_count: Some(1337), synced_at: Some(synced_at), syncing: Some(false), @@ -86,7 +86,7 @@ mod tests { discriminator: 1000, email: None, flags: None, - id: Id::new(4).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), locale: None, mfa_enabled: None, name: "user".to_owned(), @@ -192,7 +192,7 @@ mod tests { bot: None, description: "Friendship is Magic".to_string(), icon: None, - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }), @@ -201,11 +201,11 @@ mod tests { expire_behavior: Some(IntegrationExpireBehavior::Kick), expire_grace_period: Some(3_600), guild_id: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: "a".to_owned(), name: "integration name".to_owned(), revoked: Some(false), - role_id: Some(Id::new(3).expect("non zero")), + role_id: Some(Id::new_checked(3).expect("non zero")), subscriber_count: Some(1337), synced_at: Some(synced_at), syncing: Some(false), @@ -217,7 +217,7 @@ mod tests { discriminator: 1000, email: None, flags: None, - id: Id::new(4).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), locale: None, mfa_enabled: None, name: "user".to_owned(), diff --git a/model/src/guild/integration_application.rs b/model/src/guild/integration_application.rs index 6d5d3f752c3..7a5c0dc07a4 100644 --- a/model/src/guild/integration_application.rs +++ b/model/src/guild/integration_application.rs @@ -28,7 +28,7 @@ mod tests { bot: None, description: "Friendship is Magic".to_string(), icon: None, - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }; @@ -67,7 +67,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -78,7 +78,7 @@ mod tests { }), description: "Friendship is Magic".to_string(), icon: None, - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }; diff --git a/model/src/guild/member.rs b/model/src/guild/member.rs index 68557bf062f..fc0abd5a450 100644 --- a/model/src/guild/member.rs +++ b/model/src/guild/member.rs @@ -229,7 +229,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: None, deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -244,7 +244,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -325,7 +325,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: Some(communication_disabled_until), deaf: false, - guild_id: Id::new(1).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -340,7 +340,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), diff --git a/model/src/guild/mod.rs b/model/src/guild/mod.rs index 009a0d150b4..23db5f2cd4f 100644 --- a/model/src/guild/mod.rs +++ b/model/src/guild/mod.rs @@ -432,7 +432,7 @@ impl<'de> Deserialize<'de> for Guild { } let deserializer = - MemberListDeserializer::new(Id::new(1).expect("non zero")); + MemberListDeserializer::new(Id::new_checked(1).expect("non zero")); members = Some(map.next_value_seed(deserializer)?); } @@ -505,7 +505,7 @@ impl<'de> Deserialize<'de> for Guild { } let deserializer = - PresenceListDeserializer::new(Id::new(1).expect("non zero")); + PresenceListDeserializer::new(Id::new_checked(1).expect("non zero")); presences = Some(map.next_value_seed(deserializer)?); } @@ -894,9 +894,9 @@ mod tests { let joined_at = Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?; let value = Guild { - afk_channel_id: Some(Id::new(2).expect("non zero")), + afk_channel_id: Some(Id::new_checked(2).expect("non zero")), afk_timeout: 900, - application_id: Some(Id::new(3).expect("non zero")), + application_id: Some(Id::new_checked(3).expect("non zero")), approximate_member_count: Some(1_200), approximate_presence_count: Some(900), banner: Some("banner hash".to_owned()), @@ -908,7 +908,7 @@ mod tests { explicit_content_filter: ExplicitContentFilter::MembersWithoutRole, features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), joined_at: Some(joined_at), large: true, max_members: Some(25_000), @@ -919,7 +919,7 @@ mod tests { mfa_level: MfaLevel::Elevated, name: "the name".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new(5).expect("non zero"), + owner_id: Id::new_checked(5).expect("non zero"), owner: Some(false), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-us".to_owned(), @@ -927,18 +927,18 @@ mod tests { premium_tier: PremiumTier::Tier1, presences: Vec::new(), roles: Vec::new(), - rules_channel_id: Some(Id::new(6).expect("non zero")), + rules_channel_id: Some(Id::new_checked(6).expect("non zero")), splash: Some("splash hash".to_owned()), stage_instances: Vec::new(), stickers: Vec::new(), system_channel_flags: SystemChannelFlags::SUPPRESS_PREMIUM_SUBSCRIPTIONS, - system_channel_id: Some(Id::new(7).expect("non zero")), + system_channel_id: Some(Id::new_checked(7).expect("non zero")), threads: Vec::new(), unavailable: false, vanity_url_code: Some("twilight".to_owned()), verification_level: VerificationLevel::Medium, voice_states: Vec::new(), - widget_channel_id: Some(Id::new(8).expect("non zero")), + widget_channel_id: Some(Id::new_checked(8).expect("non zero")), widget_enabled: Some(true), }; diff --git a/model/src/guild/partial_guild.rs b/model/src/guild/partial_guild.rs index a7b1e3084e7..564b494fa2f 100644 --- a/model/src/guild/partial_guild.rs +++ b/model/src/guild/partial_guild.rs @@ -68,10 +68,10 @@ mod tests { #[test] fn test_partial_guild() { let value = PartialGuild { - id: Id::new(1).expect("non zero"), - afk_channel_id: Some(Id::new(2).expect("non zero")), + id: Id::new_checked(1).expect("non zero"), + afk_channel_id: Some(Id::new_checked(2).expect("non zero")), afk_timeout: 900, - application_id: Some(Id::new(3).expect("non zero")), + application_id: Some(Id::new_checked(3).expect("non zero")), banner: Some("banner hash".to_owned()), default_message_notifications: DefaultMessageNotificationLevel::Mentions, description: Some("a description".to_owned()), @@ -86,20 +86,20 @@ mod tests { mfa_level: MfaLevel::Elevated, name: "the name".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new(5).expect("non zero"), + owner_id: Id::new_checked(5).expect("non zero"), owner: Some(false), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-us".to_owned(), premium_subscription_count: Some(3), premium_tier: PremiumTier::Tier1, roles: Vec::new(), - rules_channel_id: Some(Id::new(6).expect("non zero")), + rules_channel_id: Some(Id::new_checked(6).expect("non zero")), splash: Some("splash hash".to_owned()), system_channel_flags: SystemChannelFlags::SUPPRESS_PREMIUM_SUBSCRIPTIONS, - system_channel_id: Some(Id::new(7).expect("non zero")), + system_channel_id: Some(Id::new_checked(7).expect("non zero")), verification_level: VerificationLevel::Medium, vanity_url_code: Some("twilight".to_owned()), - widget_channel_id: Some(Id::new(8).expect("non zero")), + widget_channel_id: Some(Id::new_checked(8).expect("non zero")), widget_enabled: Some(true), }; diff --git a/model/src/guild/partial_member.rs b/model/src/guild/partial_member.rs index f6c28752454..c67fdcfed1e 100644 --- a/model/src/guild/partial_member.rs +++ b/model/src/guild/partial_member.rs @@ -51,7 +51,7 @@ mod tests { nick: Some("a nickname".to_owned()), permissions: None, premium_since: None, - roles: vec![Id::new(1).expect("non zero")], + roles: vec![Id::new_checked(1).expect("non zero")], user: None, }; diff --git a/model/src/guild/preview.rs b/model/src/guild/preview.rs index 09e3fe98d70..01d428cd5e6 100644 --- a/model/src/guild/preview.rs +++ b/model/src/guild/preview.rs @@ -34,7 +34,7 @@ mod tests { emojis: vec![Emoji { animated: false, available: true, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), managed: false, name: "test".to_owned(), require_colons: true, @@ -42,7 +42,7 @@ mod tests { user: None, }], features: vec!["a feature".to_owned()], - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "guild name".to_owned(), icon: Some("icon hash".to_owned()), splash: Some("splash hash".to_owned()), diff --git a/model/src/guild/role.rs b/model/src/guild/role.rs index 84c1b5cdf08..0f272fda90a 100644 --- a/model/src/guild/role.rs +++ b/model/src/guild/role.rs @@ -57,7 +57,7 @@ impl Ord for Role { /// # use twilight_model::{guild::{Permissions, Role}, id::Id}; /// # use std::cmp::Ordering; /// let role_a = Role { - /// id: Id::new(123).expect("non zero"), + /// id: Id::new_checked(123).expect("non zero"), /// position: 12, ///# color: 0, ///# hoist: true, @@ -71,7 +71,7 @@ impl Ord for Role { /// // ... /// }; /// let role_b = Role { - /// id: Id::new(456).expect("non zero"), + /// id: Id::new_checked(456).expect("non zero"), /// position: 13, ///# color: 0, ///# hoist: true, @@ -96,7 +96,7 @@ impl Ord for Role { /// # use twilight_model::{guild::{Permissions, Role}, id::Id}; /// # use std::cmp::Ordering; /// let role_a = Role { - /// id: Id::new(123).expect("non zero"), + /// id: Id::new_checked(123).expect("non zero"), /// position: 12, ///# color: 0, ///# hoist: true, @@ -109,7 +109,7 @@ impl Ord for Role { ///# unicode_emoji: None, /// }; /// let role_b = Role { - /// id: Id::new(456).expect("non zero"), + /// id: Id::new_checked(456).expect("non zero"), /// position: 12, ///# color: 0, ///# hoist: true, @@ -178,7 +178,7 @@ mod tests { color: 0, hoist: true, icon: None, - id: Id::new(123).expect("non zero"), + id: Id::new_checked(123).expect("non zero"), managed: false, mentionable: true, name: "test".to_owned(), diff --git a/model/src/guild/role_tags.rs b/model/src/guild/role_tags.rs index af8ec0f6d92..985d1e9a4cc 100644 --- a/model/src/guild/role_tags.rs +++ b/model/src/guild/role_tags.rs @@ -77,8 +77,8 @@ mod tests { #[test] fn test_role_tags_all() { let tags = RoleTags { - bot_id: Some(Id::new(1).expect("non zero")), - integration_id: Some(Id::new(2).expect("non zero")), + bot_id: Some(Id::new_checked(1).expect("non zero")), + integration_id: Some(Id::new_checked(2).expect("non zero")), premium_subscriber: true, }; diff --git a/model/src/guild/unavailable_guild.rs b/model/src/guild/unavailable_guild.rs index 73b5f850897..c0f7acc9a37 100644 --- a/model/src/guild/unavailable_guild.rs +++ b/model/src/guild/unavailable_guild.rs @@ -16,7 +16,7 @@ mod tests { #[test] fn test_unavailable_guild() { let value = UnavailableGuild { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), unavailable: true, }; diff --git a/model/src/guild/widget.rs b/model/src/guild/widget.rs index edbb144a1f5..44e4fd49ab0 100644 --- a/model/src/guild/widget.rs +++ b/model/src/guild/widget.rs @@ -16,7 +16,7 @@ mod tests { #[test] fn test_guild_widget() { let value = GuildWidget { - channel_id: Id::new(111_111_111_111_111_111).expect("non zero"), + channel_id: Id::new_checked(111_111_111_111_111_111).expect("non zero"), enabled: true, }; diff --git a/model/src/id/mod.rs b/model/src/id/mod.rs index a4c01f936df..45309c7a56a 100644 --- a/model/src/id/mod.rs +++ b/model/src/id/mod.rs @@ -32,7 +32,7 @@ //! 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::::new(123).expect("non zero id"); +//! let guild_id = Id::::new_checked(123).expect("non zero id"); //! let role_id = guild_id.cast::(); //! //! assert_eq!(guild_id.get(), role_id.get()); @@ -87,17 +87,19 @@ impl Id { value, } } - /// Create a new non-zero ID while checking the value. + /// Create a new ID, panicking if the value is zero. /// /// This is primarily useful in const contexts where you are passing a /// hardcoded value. /// + /// Refer to [`new_checked`] for a checked alternative to this method. + /// /// # Examples /// /// ``` /// use twilight_model::id::{marker::GenericMarker, Id}; /// - /// const ID: Id = Id::new_checked(123); + /// const ID: Id = Id::new(123); /// /// println!("id: {}", ID); /// ``` @@ -105,8 +107,10 @@ impl Id { /// # Panics /// /// Panics if the value is 0. - pub const fn new_checked(n: u64) -> Self { - if let Some(id) = Self::new(n) { + /// + /// [`new_checked`]: Self::new_checked + pub const fn new(n: u64) -> Self { + if let Some(id) = Self::new_checked(n) { id } else { panic!("value passed to `Id::new_checked` is 0"); @@ -125,10 +129,20 @@ impl Id { Self::from_nonzero(NonZeroU64::new_unchecked(n)) } - /// Create a non-zero application ID if the given value is not zero. + /// Create a non-zero application ID, checking if the provided value is + /// zero. + /// + /// # Examples + /// + /// ``` + /// use twilight_model::id::{marker::GenericMarker, Id}; + /// + /// assert!(Id::::new_checked(123).is_some()); + /// assert!(Id::::new_checked(0).is_none()); + /// ``` /// /// Equivalent to [`NonZeroU64::new`]. - pub const fn new(n: u64) -> Option { + pub const fn new_checked(n: u64) -> Option { #[allow(clippy::option_if_let_else)] if let Some(n) = NonZeroU64::new(n) { Some(Self::from_nonzero(n)) @@ -149,7 +163,7 @@ impl Id { /// use twilight_model::id::{marker::ChannelMarker, Id}; /// /// # fn try_main() -> Option<()> { - /// let channel_id = Id::::new(7)?; + /// let channel_id = Id::::new_checked(7)?; /// /// assert_eq!(7, channel_id.get()); /// # Some(()) } @@ -169,7 +183,7 @@ impl Id { /// ``` /// use twilight_model::id::{marker::{GuildMarker, RoleMarker}, Id}; /// - /// let role_id: Id = Id::new(1).expect("non zero id"); + /// let role_id: Id = Id::new_checked(1).expect("non zero id"); /// /// let guild_id: Id = role_id.cast(); /// assert_eq!(1, guild_id.get()); @@ -192,7 +206,7 @@ impl Id { /// id::{marker::UserMarker, Id}, /// }; /// - /// let id = Id::::new(105484726235607040).expect("non zero"); + /// let id = Id::::new_checked(105484726235607040).expect("non zero"); /// /// assert_eq!(id.timestamp(), 1445219918546); /// @@ -507,12 +521,12 @@ mod tests { /// [`Id::new`] or [`Id`]'s [`TryFrom`] implementations. #[test] fn test_initializers() -> Result<(), Box> { - // `Id::new` - assert!(Id::::new(0).is_none()); - assert_eq!(Some(1), Id::::new(1).map(Id::get)); - // `Id::new_checked` - assert_eq!(1, Id::::new_checked(1).get()); + assert!(Id::::new_checked(0).is_none()); + assert_eq!(Some(1), Id::::new_checked(1).map(Id::get)); + + // `Id::new` + assert_eq!(1, Id::::new(1).get()); // `From` assert_eq!( @@ -535,24 +549,24 @@ mod tests { Ok(()) } - /// Test that creating a checked ID with a value of 0 + /// Test that creating an ID via [`Id::new`] with a value of zero panics. #[should_panic] #[test] const fn test_new_checked_zero() { - let _ = Id::::new_checked(0); + let _ = Id::::new(0); } /// Test that casting IDs maintains the original value. #[test] fn test_cast() { - let id = Id::::new(123).expect("non zero"); + let id = Id::::new_checked(123).expect("non zero"); 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).expect("non zero"); + let id = Id::::new_checked(105_484_726_235_607_040).expect("non zero"); assert_eq!(expected, id.timestamp()) } @@ -560,7 +574,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_checked(762_022_344_856_174_632).expect("non zero"); assert_eq!(expected, id.worker_id()) } @@ -568,7 +582,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_checked(61_189_081_970_774_016).expect("non zero"); assert_eq!(expected, id.process_id()) } @@ -576,7 +590,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_checked(762_022_344_856_174_632).expect("non zero"); assert_eq!(expected, id.increment()) } @@ -584,7 +598,7 @@ mod tests { /// Test that debugging IDs formats the generic and value as a newtype. #[test] fn test_debug() { - let id = Id::::new(114_941_315_417_899_012).expect("non zero"); + let id = Id::::new_checked(114_941_315_417_899_012).expect("non zero"); assert_eq!("Id(114941315417899012)", format!("{:?}", id)); } @@ -592,7 +606,7 @@ mod tests { /// Test that display formatting an ID formats the value. #[test] fn test_display() { - let id = Id::::new(114_941_315_417_899_012).expect("non zero"); + let id = Id::::new_checked(114_941_315_417_899_012).expect("non zero"); assert_eq!("114941315417899012", id.to_string()); } @@ -600,7 +614,7 @@ mod tests { /// Test that hashing an ID is equivalent to hashing only its inner value. #[test] fn test_hash() { - let id = Id::::new(123).expect("non zero"); + let id = Id::::new_checked(123).expect("non zero"); let mut id_hasher = DefaultHasher::new(); id.hash(&mut id_hasher); @@ -614,9 +628,9 @@ mod tests { /// Test that IDs are ordered exactly like their inner values. #[test] fn test_ordering() { - let lesser = Id::::new(911_638_235_594_244_096).expect("non zero"); - let center = Id::::new(911_638_263_322_800_208).expect("non zero"); - let greater = Id::::new(911_638_287_939_166_208).expect("non zero"); + let lesser = Id::::new_checked(911_638_235_594_244_096).expect("non zero"); + let center = Id::::new_checked(911_638_263_322_800_208).expect("non zero"); + let greater = Id::::new_checked(911_638_287_939_166_208).expect("non zero"); assert!(center.cmp(&greater).is_lt()); assert!(center.cmp(¢er).is_eq()); @@ -627,224 +641,224 @@ mod tests { #[test] fn test_serde() { serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new(114_941_315_417_899_012).expect("non zero"), + &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), diff --git a/model/src/invite/channel.rs b/model/src/invite/channel.rs index 0d49453f599..ca9907f42ef 100644 --- a/model/src/invite/channel.rs +++ b/model/src/invite/channel.rs @@ -25,7 +25,7 @@ mod tests { #[test] fn test_invite_channel() { let value = InviteChannel { - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: Some("channel name".to_owned()), kind: ChannelType::GuildText, }; diff --git a/model/src/invite/guild.rs b/model/src/invite/guild.rs index 1e0b8633d22..2bfc1d2325f 100644 --- a/model/src/invite/guild.rs +++ b/model/src/invite/guild.rs @@ -43,7 +43,7 @@ mod tests { description: Some("a description".to_owned()), features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "guild name".to_owned(), splash: Some("splash hash".to_owned()), vanity_url_code: Some("twilight".to_owned()), @@ -52,15 +52,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new(123).expect("non zero"), + channel_id: Id::new_checked(123).expect("non zero"), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new(456).expect("non zero"), + channel_id: Id::new_checked(456).expect("non zero"), description: "custom description".to_owned(), - emoji_id: Some(Id::new(789).expect("non zero")), + emoji_id: Some(Id::new_checked(789).expect("non zero")), emoji_name: Some("custom_name".to_owned()), }, ], diff --git a/model/src/invite/mod.rs b/model/src/invite/mod.rs index 3b05c5a71dc..4fd57220253 100644 --- a/model/src/invite/mod.rs +++ b/model/src/invite/mod.rs @@ -100,7 +100,7 @@ mod tests { approximate_member_count: Some(31), approximate_presence_count: Some(7), channel: Some(InviteChannel { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::Group, name: None, }), @@ -164,7 +164,7 @@ mod tests { approximate_member_count: Some(31), approximate_presence_count: Some(7), channel: Some(InviteChannel { - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::Group, name: None, }), @@ -176,7 +176,7 @@ mod tests { description: Some("a description".to_owned()), features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), name: "guild name".to_owned(), splash: Some("splash hash".to_owned()), vanity_url_code: Some("twilight".to_owned()), @@ -185,15 +185,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new(123).expect("non zero"), + channel_id: Id::new_checked(123).expect("non zero"), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new(456).expect("non zero"), + channel_id: Id::new_checked(456).expect("non zero"), description: "custom description".to_owned(), - emoji_id: Some(Id::new(789).expect("non zero")), + emoji_id: Some(Id::new_checked(789).expect("non zero")), emoji_name: Some("custom_name".to_owned()), }, ], @@ -207,7 +207,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -234,7 +234,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -257,7 +257,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/invite/welcome_screen.rs b/model/src/invite/welcome_screen.rs index b6510537d3e..23d9bec81bb 100644 --- a/model/src/invite/welcome_screen.rs +++ b/model/src/invite/welcome_screen.rs @@ -36,15 +36,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new(123).expect("non zero"), + channel_id: Id::new_checked(123).expect("non zero"), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new(456).expect("non zero"), + channel_id: Id::new_checked(456).expect("non zero"), description: "custom description".to_owned(), - emoji_id: Some(Id::new(789).expect("non zero")), + emoji_id: Some(Id::new_checked(789).expect("non zero")), emoji_name: Some("custom_name".to_owned()), }, ], diff --git a/model/src/oauth/current_application_info/mod.rs b/model/src/oauth/current_application_info/mod.rs index a267147067a..7c67209c25e 100644 --- a/model/src/oauth/current_application_info/mod.rs +++ b/model/src/oauth/current_application_info/mod.rs @@ -88,10 +88,10 @@ mod tests { bot_require_code_grant: false, cover_image: Some("cover image hash".to_owned()), description: "a pretty cool application".to_owned(), - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), flags: Some(ApplicationFlags::EMBEDDED), icon: Some("icon hash".to_owned()), - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), name: "cool application".to_owned(), owner: User { accent_color: None, @@ -101,7 +101,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "app dev".to_owned(), @@ -110,17 +110,17 @@ mod tests { system: None, verified: None, }, - primary_sku_id: Some(Id::new(4).expect("non zero")), + primary_sku_id: Some(Id::new_checked(4).expect("non zero")), privacy_policy_url: Some("https://privacypolicy".into()), rpc_origins: vec!["one".to_owned()], slug: Some("app slug".to_owned()), summary: "a summary".to_owned(), team: Some(Team { icon: None, - id: Id::new(5).expect("non zero"), + id: Id::new_checked(5).expect("non zero"), members: Vec::new(), name: "team name".into(), - owner_user_id: Id::new(6).expect("non zero"), + owner_user_id: Id::new_checked(6).expect("non zero"), }), terms_of_service_url: Some("https://termsofservice".into()), verify_key: "key".to_owned(), diff --git a/model/src/oauth/team/member.rs b/model/src/oauth/team/member.rs index e0068628214..ee0e7f6f818 100644 --- a/model/src/oauth/team/member.rs +++ b/model/src/oauth/team/member.rs @@ -24,7 +24,7 @@ mod tests { let value = TeamMember { membership_state: TeamMembershipState::Accepted, permissions: vec!["*".to_owned()], - team_id: Id::new(1).expect("non zero"), + team_id: Id::new_checked(1).expect("non zero"), user: User { accent_color: None, avatar: None, @@ -33,7 +33,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/oauth/team/mod.rs b/model/src/oauth/team/mod.rs index fc34ac0f060..14f0c76e8b6 100644 --- a/model/src/oauth/team/mod.rs +++ b/model/src/oauth/team/mod.rs @@ -43,10 +43,10 @@ mod tests { fn test_team() { let value = Team { icon: Some("hash".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), members: Vec::new(), name: "team name".into(), - owner_user_id: Id::new(2).expect("non zero"), + owner_user_id: Id::new_checked(2).expect("non zero"), }; serde_test::assert_tokens( diff --git a/model/src/template/mod.rs b/model/src/template/mod.rs index b5acec02cbc..9416a8ee1fb 100644 --- a/model/src/template/mod.rs +++ b/model/src/template/mod.rs @@ -187,7 +187,7 @@ mod tests { email: None, discriminator: 1111, flags: None, - id: Id::new(100).expect("non zero"), + id: Id::new_checked(100).expect("non zero"), locale: None, mfa_enabled: None, name: "username".into(), @@ -196,7 +196,7 @@ mod tests { system: None, verified: None, }, - creator_id: Id::new(100).expect("non zero"), + creator_id: Id::new_checked(100).expect("non zero"), description: Some("description".into()), is_dirty: None, name: "name".into(), @@ -206,7 +206,7 @@ mod tests { channels: vec![ GuildChannel::Category(CategoryChannel { guild_id: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), kind: ChannelType::GuildCategory, name: "Text Channels".into(), permission_overwrites: vec![], @@ -214,23 +214,23 @@ mod tests { }), GuildChannel::Text(TextChannel { guild_id: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, name: "general".into(), nsfw: false, - parent_id: Some(Id::new(1).expect("non zero")), + parent_id: Some(Id::new_checked(1).expect("non zero")), permission_overwrites: vec![ PermissionOverwrite { allow: Permissions::from_bits(0).unwrap(), deny: Permissions::from_bits(2048).unwrap(), - kind: PermissionOverwriteType::Role(Id::new(1).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(1).expect("non zero")), }, PermissionOverwrite { allow: Permissions::from_bits(2048).unwrap(), deny: Permissions::from_bits(0).unwrap(), - kind: PermissionOverwriteType::Role(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), }, ], position: 0, @@ -239,7 +239,7 @@ mod tests { }), GuildChannel::Category(CategoryChannel { guild_id: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), kind: ChannelType::GuildCategory, name: "Voice Channels".into(), permission_overwrites: vec![], @@ -248,10 +248,10 @@ mod tests { GuildChannel::Voice(VoiceChannel { bitrate: 64000, guild_id: None, - id: Id::new(4).expect("non zero"), + id: Id::new_checked(4).expect("non zero"), kind: ChannelType::GuildVoice, name: "General".into(), - parent_id: Some(Id::new(3).expect("non zero")), + parent_id: Some(Id::new_checked(3).expect("non zero")), permission_overwrites: vec![], rtc_region: None, position: 0, @@ -269,7 +269,7 @@ mod tests { TemplateRole { color: 0, hoist: false, - id: Id::new(200).expect("non zero"), + id: Id::new_checked(200).expect("non zero"), mentionable: false, name: "@everyone".into(), permissions: Permissions::CREATE_INVITE @@ -291,7 +291,7 @@ mod tests { TemplateRole { color: 0, hoist: false, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), mentionable: false, name: "new role".into(), permissions: Permissions::CREATE_INVITE @@ -312,10 +312,10 @@ mod tests { }, ], system_channel_flags: SystemChannelFlags::empty(), - system_channel_id: Some(Id::new(2).expect("non zero")), + system_channel_id: Some(Id::new_checked(2).expect("non zero")), verification_level: VerificationLevel::None, }, - source_guild_id: Id::new(200).expect("non zero"), + source_guild_id: Id::new_checked(200).expect("non zero"), updated_at, usage_count: 0, }; diff --git a/model/src/user/current_user.rs b/model/src/user/current_user.rs index 8137fd40386..51d8a6c9dd9 100644 --- a/model/src/user/current_user.rs +++ b/model/src/user/current_user.rs @@ -178,7 +178,7 @@ mod tests { bot: true, discriminator: 9999, email: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), mfa_enabled: true, name: "test name".to_owned(), verified: Some(true), @@ -207,7 +207,7 @@ mod tests { bot: true, discriminator: 9999, email: Some("test@example.com".to_owned()), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), mfa_enabled: true, name: "test name".to_owned(), verified: Some(true), diff --git a/model/src/user/current_user_guild.rs b/model/src/user/current_user_guild.rs index 9ef16df86ae..e95b594fe29 100644 --- a/model/src/user/current_user_guild.rs +++ b/model/src/user/current_user_guild.rs @@ -42,7 +42,7 @@ mod tests { fn test_current_user_guild() { // The example partial guild from the discord docs let value = CurrentUserGuild { - id: Id::new(80_351_110_224_678_912).expect("non zero"), + id: Id::new_checked(80_351_110_224_678_912).expect("non zero"), name: "abcd".to_owned(), icon: Some("8342729096ea3675442027381ff50dfe".to_owned()), owner: true, diff --git a/model/src/user/mod.rs b/model/src/user/mod.rs index f48f8c13837..5c51d3bf989 100644 --- a/model/src/user/mod.rs +++ b/model/src/user/mod.rs @@ -305,7 +305,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), @@ -335,7 +335,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/user/profile.rs b/model/src/user/profile.rs index d4fc1076ff1..28a8beccf88 100644 --- a/model/src/user/profile.rs +++ b/model/src/user/profile.rs @@ -109,7 +109,7 @@ mod tests { discriminator: 4, email: Some("email@example.com".to_owned()), flags: Some(UserFlags::VERIFIED_DEVELOPER), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "user name".to_owned(), diff --git a/model/src/voice/voice_state.rs b/model/src/voice/voice_state.rs index ce0f72813bb..2e321c36e30 100644 --- a/model/src/voice/voice_state.rs +++ b/model/src/voice/voice_state.rs @@ -149,7 +149,7 @@ impl<'de> Visitor<'de> for VoiceStateVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); member = map.next_value_seed(deserializer)?; } @@ -302,9 +302,9 @@ mod tests { #[test] fn test_voice_state() { let value = VoiceState { - channel_id: Some(Id::new(1).expect("non zero")), + channel_id: Some(Id::new_checked(1).expect("non zero")), deaf: false, - guild_id: Some(Id::new(2).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), member: None, mute: true, self_deaf: false, @@ -313,7 +313,7 @@ mod tests { session_id: "a".to_owned(), suppress: true, token: None, - user_id: Id::new(3).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), request_to_speak_timestamp: None, }; @@ -364,14 +364,14 @@ mod tests { let request_to_speak_timestamp = Timestamp::from_str("2021-04-21T22:16:50.000000+00:00")?; let value = VoiceState { - channel_id: Some(Id::new(1).expect("non zero")), + channel_id: Some(Id::new_checked(1).expect("non zero")), deaf: false, - guild_id: Some(Id::new(2).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(2).expect("non zero"), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -386,7 +386,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -403,7 +403,7 @@ mod tests { session_id: "a".to_owned(), suppress: true, token: Some("abc".to_owned()), - user_id: Id::new(3).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), request_to_speak_timestamp: Some(request_to_speak_timestamp), }; diff --git a/standby/README.md b/standby/README.md index df322909490..e1639d3f211 100644 --- a/standby/README.md +++ b/standby/README.md @@ -59,7 +59,7 @@ use twilight_standby::Standby; let standby = Standby::new(); -let channel_id = Id::new(123).expect("non zero"); +let channel_id = Id::new_checked(123).expect("non zero"); let message = standby.wait_for_message(channel_id, |event: &MessageCreate| { event.author.id.get() == 456 && event.content == "test" diff --git a/standby/src/lib.rs b/standby/src/lib.rs index 60d2baf6e58..e6ba08ed78c 100644 --- a/standby/src/lib.rs +++ b/standby/src/lib.rs @@ -58,7 +58,7 @@ //! //! let standby = Standby::new(); //! -//! let channel_id = Id::new(123).expect("non zero"); +//! let channel_id = Id::new_checked(123).expect("non zero"); //! //! let message = standby.wait_for_message(channel_id, |event: &MessageCreate| { //! event.author.id.get() == 456 && event.content == "test" @@ -348,7 +348,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let guild_id = Id::new(123).expect("non zero"); + /// let guild_id = Id::new_checked(123).expect("non zero"); /// /// let reaction = standby.wait_for(guild_id, |event: &Event| { /// event.kind() == EventType::BanAdd @@ -398,7 +398,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let guild_id = Id::new(123).expect("non zero"); + /// let guild_id = Id::new_checked(123).expect("non zero"); /// /// let mut stream = standby.wait_for_stream(guild_id, |event: &Event| { /// event.kind() == EventType::BanAdd @@ -574,8 +574,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let author_id = Id::new(456).expect("non zero"); - /// let channel_id = Id::new(123).expect("non zero"); + /// let author_id = Id::new_checked(456).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// /// let message = standby.wait_for_message(channel_id, move |event: &MessageCreate| { /// event.author.id == author_id && event.content == "test" @@ -625,8 +625,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let author_id = Id::new(456).expect("non zero"); - /// let channel_id = Id::new(123).expect("non zero"); + /// let author_id = Id::new_checked(456).expect("non zero"); + /// let channel_id = Id::new_checked(123).expect("non zero"); /// /// let mut messages = standby.wait_for_message_stream(channel_id, move |event: &MessageCreate| { /// event.author.id == author_id && event.content == "test" @@ -678,8 +678,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let message_id = Id::new(123).expect("non zero"); - /// let user_id = Id::new(456).expect("non zero"); + /// let message_id = Id::new_checked(123).expect("non zero"); + /// let user_id = Id::new_checked(456).expect("non zero"); /// /// let reaction = standby.wait_for_reaction(message_id, move |event: &ReactionAdd| { /// event.user_id == user_id @@ -729,7 +729,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let message_id = Id::new(123).expect("non zero"); + /// let message_id = Id::new_checked(123).expect("non zero"); /// /// let mut reactions = standby.wait_for_reaction_stream(message_id, |event: &ReactionAdd| { /// matches!(&event.emoji, ReactionType::Unicode { name } if name == "🤠") @@ -781,10 +781,10 @@ impl Standby { /// use twilight_standby::Standby; /// /// let standby = Standby::new(); - /// let message_id = Id::new(123).expect("non zero"); + /// let message_id = Id::new_checked(123).expect("non zero"); /// /// let component = standby.wait_for_component(message_id, |event: &MessageComponentInteraction| { - /// event.author_id() == Some(Id::new(456).expect("non zero")) + /// event.author_id() == Some(Id::new_checked(456).expect("non zero")) /// }).await?; /// # Ok(()) } /// ``` @@ -826,7 +826,7 @@ impl Standby { /// use twilight_standby::Standby; /// /// let standby = Standby::new(); - /// let message_id = Id::new(123).expect("non zero"); + /// let message_id = Id::new_checked(123).expect("non zero"); /// /// let mut components = standby.wait_for_component_stream(message_id, |event: &MessageComponentInteraction| { /// event.data.custom_id == "Click".to_string() @@ -1243,7 +1243,7 @@ mod tests { fn message() -> Message { Message { - id: Id::new(3).expect("non zero"), + id: Id::new_checked(3).expect("non zero"), activity: None, application: None, application_id: None, @@ -1256,7 +1256,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -1265,13 +1265,13 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new(1).expect("non zero"), + channel_id: Id::new_checked(1).expect("non zero"), components: Vec::new(), content: "test".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: None, - guild_id: Some(Id::new(4).expect("non zero")), + guild_id: Some(Id::new_checked(4).expect("non zero")), interaction: None, kind: MessageType::Regular, member: None, @@ -1293,28 +1293,28 @@ mod tests { fn reaction() -> Reaction { Reaction { - channel_id: Id::new(2).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), emoji: ReactionType::Unicode { name: "🍎".to_owned(), }, - guild_id: Some(Id::new(1).expect("non zero")), + guild_id: Some(Id::new_checked(1).expect("non zero")), member: None, - message_id: Id::new(4).expect("non zero"), - user_id: Id::new(3).expect("non zero"), + message_id: Id::new_checked(4).expect("non zero"), + user_id: Id::new_checked(3).expect("non zero"), } } fn button() -> MessageComponentInteraction { MessageComponentInteraction { - application_id: Id::new(1).expect("non zero"), - channel_id: Id::new(2).expect("non zero"), + application_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new_checked(2).expect("non zero"), data: MessageComponentInteractionData { custom_id: String::from("Click"), component_type: ComponentType::Button, values: vec![], }, - guild_id: Some(Id::new(3).expect("non zero")), - id: Id::new(4).expect("non zero"), + guild_id: Some(Id::new_checked(3).expect("non zero")), + id: Id::new_checked(4).expect("non zero"), kind: InteractionType::MessageComponent, member: None, message: message(), @@ -1327,7 +1327,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new(2).expect("non zero"), + id: Id::new_checked(2).expect("non zero"), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -1344,7 +1344,7 @@ mod tests { #[tokio::test] async fn test_dropped() { let standby = Standby::new(); - let guild_id = Id::new(1).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); { let _rx = standby.wait_for(guild_id, move |_: &Event| false); @@ -1352,7 +1352,7 @@ mod tests { let results = standby.process(&Event::RoleDelete(RoleDelete { guild_id, - role_id: Id::new(2).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); assert_eq!(1, results.dropped()); @@ -1369,8 +1369,8 @@ mod tests { } let standby = Standby::new(); - let guild_id_one = Id::new(1).expect("non zero"); - let guild_id_two = Id::new(2).expect("non zero"); + let guild_id_one = Id::new_checked(1).expect("non zero"); + let guild_id_two = Id::new_checked(2).expect("non zero"); let _one = standby.wait_for(guild_id_one, move |event: &Event| { check(event, guild_id_one) }); @@ -1382,8 +1382,8 @@ mod tests { }); let results = standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); assert_eq!(0, results.dropped()); @@ -1396,13 +1396,13 @@ mod tests { #[tokio::test] async fn test_sent() { let standby = Standby::new(); - let guild_id = Id::new(1).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); let _rx = standby.wait_for_stream(guild_id, move |_: &Event| true); let results = standby.process(&Event::RoleDelete(RoleDelete { guild_id, - role_id: Id::new(2).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); assert_eq!(0, results.dropped()); @@ -1415,19 +1415,19 @@ mod tests { async fn test_wait_for() { let standby = Standby::new(); let wait = standby.wait_for( - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), |event: &Event| matches!(event, Event::RoleDelete(e) if e.guild_id.get() == 1), ); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); assert_eq!( wait.await.unwrap(), Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), }) ); assert!(standby.guilds.is_empty()); @@ -1438,37 +1438,37 @@ mod tests { async fn test_wait_for_stream() { let standby = Standby::new(); let mut stream = standby.wait_for_stream( - Id::new(1).expect("non zero"), + Id::new_checked(1).expect("non zero"), |event: &Event| matches!(event, Event::RoleDelete(e) if e.guild_id.get() == 1), ); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(3).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(3).expect("non zero"), })); assert_eq!( stream.next().await, Some(Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero") + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero") })) ); assert_eq!( stream.next().await, Some(Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(3).expect("non zero") + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(3).expect("non zero") })) ); assert!(!standby.guilds.is_empty()); drop(stream); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(4).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(4).expect("non zero"), })); assert!(standby.guilds.is_empty()); } @@ -1479,7 +1479,7 @@ mod tests { let ready = Ready { application: PartialApplication { flags: ApplicationFlags::empty(), - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), }, guilds: Vec::new(), session_id: String::new(), @@ -1491,7 +1491,7 @@ mod tests { bot: false, discriminator: 1, email: None, - id: Id::new(1).expect("non zero"), + id: Id::new_checked(1).expect("non zero"), mfa_enabled: true, name: "twilight".to_owned(), verified: Some(false), @@ -1539,7 +1539,7 @@ mod tests { let standby = Standby::new(); let wait = standby - .wait_for_message(Id::new(1).expect("non zero"), |message: &MessageCreate| { + .wait_for_message(Id::new_checked(1).expect("non zero"), |message: &MessageCreate| { message.author.id.get() == 2 }); standby.process(&event); @@ -1554,7 +1554,7 @@ mod tests { async fn test_wait_for_message_stream() { let standby = Standby::new(); let mut stream = standby - .wait_for_message_stream(Id::new(1).expect("non zero"), |_: &MessageCreate| true); + .wait_for_message_stream(Id::new_checked(1).expect("non zero"), |_: &MessageCreate| true); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); @@ -1573,14 +1573,14 @@ mod tests { let standby = Standby::new(); let wait = standby - .wait_for_reaction(Id::new(4).expect("non zero"), |reaction: &ReactionAdd| { + .wait_for_reaction(Id::new_checked(4).expect("non zero"), |reaction: &ReactionAdd| { reaction.user_id.get() == 3 }); standby.process(&event); assert_eq!( - Id::new(3).expect("non zero"), + Id::new_checked(3).expect("non zero"), wait.await.map(|reaction| reaction.user_id).unwrap() ); assert!(standby.reactions.is_empty()); @@ -1592,7 +1592,7 @@ mod tests { async fn test_wait_for_reaction_stream() { let standby = Standby::new(); let mut stream = - standby.wait_for_reaction_stream(Id::new(4).expect("non zero"), |_: &ReactionAdd| true); + standby.wait_for_reaction_stream(Id::new_checked(4).expect("non zero"), |_: &ReactionAdd| true); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); @@ -1614,16 +1614,16 @@ mod tests { let standby = Standby::new(); let wait = standby.wait_for_component( - Id::new(3).expect("non zero"), + Id::new_checked(3).expect("non zero"), |button: &MessageComponentInteraction| { - button.author_id() == Some(Id::new(2).expect("non zero")) + button.author_id() == Some(Id::new_checked(2).expect("non zero")) }, ); standby.process(&event); assert_eq!( - Some(Id::new(2).expect("non zero")), + Some(Id::new_checked(2).expect("non zero")), wait.await.map(|button| button.author_id()).unwrap() ); assert!(standby.components.is_empty()); @@ -1633,7 +1633,7 @@ mod tests { async fn test_wait_for_component_stream() { let standby = Standby::new(); let mut stream = standby.wait_for_component_stream( - Id::new(3).expect("non zero"), + Id::new_checked(3).expect("non zero"), |_: &MessageComponentInteraction| true, ); standby.process(&Event::InteractionCreate(Box::new(InteractionCreate( @@ -1686,13 +1686,13 @@ mod tests { // generic event handler gets other guild events let wait = standby.wait_for_event(|event: &Event| event.kind() == EventType::RoleDelete); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new(1).expect("non zero"), - role_id: Id::new(2).expect("non zero"), + guild_id: Id::new_checked(1).expect("non zero"), + role_id: Id::new_checked(2).expect("non zero"), })); assert!(matches!(wait.await, Ok(Event::RoleDelete(_)))); // guild event handler gets message creates or reaction events - let wait = standby.wait_for(Id::new(1).expect("non zero"), |event: &Event| { + let wait = standby.wait_for(Id::new_checked(1).expect("non zero"), |event: &Event| { event.kind() == EventType::ReactionAdd }); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); diff --git a/util/src/builder/command.rs b/util/src/builder/command.rs index 73e8fc09ff1..ffdfd2a506c 100644 --- a/util/src/builder/command.rs +++ b/util/src/builder/command.rs @@ -55,7 +55,7 @@ impl CommandBuilder { kind, name, options: Vec::new(), - version: Id::new(1).expect("non zero"), + version: Id::new_checked(1).expect("non zero"), }) } @@ -817,7 +817,7 @@ mod tests { ]), }), ]), - version: Id::new(1).expect("non zero"), + version: Id::new_checked(1).expect("non zero"), }; assert_eq!(command, command_manual); diff --git a/util/src/link/webhook.rs b/util/src/link/webhook.rs index 70788bd35bc..7c9e1eb161f 100644 --- a/util/src/link/webhook.rs +++ b/util/src/link/webhook.rs @@ -87,7 +87,7 @@ pub enum WebhookParseErrorType { /// let url = "https://canary.discord.com/api/webhooks/794590023369752587/tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"; /// /// let (id, token) = webhook::parse(url)?; -/// assert_eq!(Id::new(794590023369752587).expect("non zero"), id); +/// assert_eq!(Id::new_checked(794590023369752587).expect("non zero"), id); /// assert_eq!( /// Some("tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"), /// token, @@ -105,7 +105,7 @@ pub enum WebhookParseErrorType { /// let url = "https://canary.discord.com/api/webhooks/794590023369752587"; /// /// let (id, token) = webhook::parse(url)?; -/// assert_eq!(Id::new(794590023369752587).expect("non zero"), id); +/// assert_eq!(Id::new_checked(794590023369752587).expect("non zero"), id); /// assert!(token.is_none()); /// # Ok(()) } /// ``` @@ -171,13 +171,13 @@ mod tests { #[test] fn test_parse_no_token() { assert_eq!( - (Id::new(123).expect("non zero"), None), + (Id::new_checked(123).expect("non zero"), None), super::parse("https://discord.com/api/webhooks/123").unwrap(), ); // There's a / after the ID signifying another segment, but the token // ends up being None. assert_eq!( - (Id::new(123).expect("non zero"), None), + (Id::new_checked(123).expect("non zero"), None), super::parse("https://discord.com/api/webhooks/123").unwrap(), ); assert!(super::parse("https://discord.com/api/webhooks/123/") @@ -190,24 +190,24 @@ mod tests { fn test_parse_with_token() { assert_eq!( super::parse("https://discord.com/api/webhooks/456/token").unwrap(), - (Id::new(456).expect("non zero"), Some("token")), + (Id::new_checked(456).expect("non zero"), Some("token")), ); // The value of the segment(s) after the token are ignored. assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/github").unwrap(), - (Id::new(456).expect("non zero"), Some("token")), + (Id::new_checked(456).expect("non zero"), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/slack").unwrap(), - (Id::new(456).expect("non zero"), Some("token")), + (Id::new_checked(456).expect("non zero"), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/randomsegment").unwrap(), - (Id::new(456).expect("non zero"), Some("token")), + (Id::new_checked(456).expect("non zero"), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/one/two/three").unwrap(), - (Id::new(456).expect("non zero"), Some("token")), + (Id::new_checked(456).expect("non zero"), Some("token")), ); } diff --git a/util/src/permission_calculator/mod.rs b/util/src/permission_calculator/mod.rs index 29bdaf41582..ec0fb5db335 100644 --- a/util/src/permission_calculator/mod.rs +++ b/util/src/permission_calculator/mod.rs @@ -41,8 +41,8 @@ //! id::Id, //! }; //! -//! let guild_id = Id::new(1).expect("non zero"); -//! let user_id = Id::new(3).expect("non zero"); +//! let guild_id = Id::new_checked(1).expect("non zero"); +//! let user_id = Id::new_checked(3).expect("non zero"); //! //! // Guild-level @everyone role that, by default, allows everyone to view //! // channels. @@ -53,7 +53,7 @@ //! let member_roles = &[ //! // Guild-level permission that grants members with the role the Send //! // Messages permission. -//! (Id::new(2).expect("non zero"), Permissions::SEND_MESSAGES), +//! (Id::new_checked(2).expect("non zero"), Permissions::SEND_MESSAGES), //! ]; //! //! let channel_overwrites = &[ @@ -62,7 +62,7 @@ //! PermissionOverwrite { //! allow: Permissions::ADD_REACTIONS | Permissions::EMBED_LINKS, //! deny: Permissions::empty(), -//! kind: PermissionOverwriteType::Role(Id::new(1).expect("non zero")), +//! kind: PermissionOverwriteType::Role(Id::new_checked(1).expect("non zero")), //! }, //! // Member is denied the Send Messages permission. //! PermissionOverwrite { @@ -534,8 +534,8 @@ mod tests { #[test] fn test_owner_is_admin() { - let guild_id = Id::new(1).expect("non zero"); - let user_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let everyone_role = Permissions::SEND_MESSAGES; let roles = &[]; @@ -549,10 +549,10 @@ mod tests { // implicitly denies all other permissions. #[test] fn test_view_channel_deny_implicit() { - let guild_id = Id::new(1).expect("non zero"); - let user_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let everyone_role = Permissions::MENTION_EVERYONE | Permissions::SEND_MESSAGES; - let roles = &[(Id::new(3).expect("non zero"), Permissions::empty())]; + let roles = &[(Id::new_checked(3).expect("non zero"), Permissions::empty())]; { // First, test when it's denied for an overwrite on a role the user @@ -560,7 +560,7 @@ mod tests { let overwrites = &[PermissionOverwrite { allow: Permissions::SEND_TTS_MESSAGES, deny: Permissions::VIEW_CHANNEL, - kind: PermissionOverwriteType::Role(Id::new(3).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(3).expect("non zero")), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -574,7 +574,7 @@ mod tests { let overwrites = &[PermissionOverwrite { allow: Permissions::SEND_TTS_MESSAGES, deny: Permissions::VIEW_CHANNEL, - kind: PermissionOverwriteType::Member(Id::new(2).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new_checked(2).expect("non zero")), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -586,10 +586,13 @@ mod tests { #[test] fn test_remove_text_and_stage_perms_when_voice() { - let guild_id = Id::new(1).expect("non zero"); - let user_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let everyone_role = Permissions::CONNECT; - let roles = &[(Id::new(3).expect("non zero"), Permissions::SEND_MESSAGES)]; + let roles = &[( + Id::new_checked(3).expect("non zero"), + Permissions::SEND_MESSAGES, + )]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) .in_channel(ChannelType::GuildVoice, &[]); @@ -599,10 +602,13 @@ mod tests { #[test] fn test_remove_audio_perms_when_text() { - let guild_id = Id::new(1).expect("non zero"); - let user_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let everyone_role = Permissions::CONNECT; - let roles = &[(Id::new(3).expect("non zero"), Permissions::SEND_MESSAGES)]; + let roles = &[( + Id::new_checked(3).expect("non zero"), + Permissions::SEND_MESSAGES, + )]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) .in_channel(ChannelType::GuildText, &[]); @@ -616,17 +622,17 @@ mod tests { // send related permissions. #[test] fn test_deny_send_messages_removes_related() { - let guild_id = Id::new(1).expect("non zero"); - let user_id = Id::new(2).expect("non zero"); + let guild_id = Id::new_checked(1).expect("non zero"); + let user_id = Id::new_checked(2).expect("non zero"); let everyone_role = Permissions::MANAGE_MESSAGES | Permissions::EMBED_LINKS | Permissions::MENTION_EVERYONE; - let roles = &[(Id::new(3).expect("non zero"), Permissions::empty())]; + let roles = &[(Id::new_checked(3).expect("non zero"), Permissions::empty())]; // First, test when it's denied for an overwrite on a role the user has. let overwrites = &[PermissionOverwrite { allow: Permissions::ATTACH_FILES, deny: Permissions::SEND_MESSAGES, - kind: PermissionOverwriteType::Role(Id::new(3).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new_checked(3).expect("non zero")), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -639,10 +645,13 @@ mod tests { /// has all denying overwrites ignored. #[test] fn test_admin() { - let member_roles = &[(Id::new(3).expect("non zero"), Permissions::ADMINISTRATOR)]; + let member_roles = &[( + Id::new_checked(3).expect("non zero"), + Permissions::ADMINISTRATOR, + )]; let calc = PermissionCalculator::new( - Id::new(1).expect("non zero"), - Id::new(2).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(2).expect("non zero"), Permissions::empty(), member_roles, ); @@ -673,8 +682,8 @@ mod tests { for kind in CHANNEL_TYPES { let calc = PermissionCalculator::new( - Id::new(1).expect("non zero"), - Id::new(2).expect("non zero"), + Id::new_checked(1).expect("non zero"), + Id::new_checked(2).expect("non zero"), everyone, &[], ); diff --git a/validate/src/command.rs b/validate/src/command.rs index 63181fa859c..8f861671142 100644 --- a/validate/src/command.rs +++ b/validate/src/command.rs @@ -374,15 +374,15 @@ mod tests { #[test] fn test_command() { let valid_command = Command { - application_id: Some(Id::new(1).expect("non zero")), + application_id: Some(Id::new_checked(1).expect("non zero")), default_permission: None, description: "a".repeat(100), - guild_id: Some(Id::new(2).expect("non zero")), - id: Some(Id::new(3).expect("non zero")), + guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Some(Id::new_checked(3).expect("non zero")), kind: CommandType::ChatInput, name: "b".repeat(32), options: Vec::new(), - version: Id::new(4).expect("non zero"), + version: Id::new_checked(4).expect("non zero"), }; assert!(command(&valid_command).is_ok()); From 0da8181351de85c1617fa27c6407feb4633ac912 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:12:17 -0500 Subject: [PATCH 05/13] left some out Signed-off-by: Zeyla Hellyer --- cache/in-memory/src/event/interaction.rs | 18 +++++++-- cache/in-memory/src/event/member.rs | 21 +++++----- cache/in-memory/src/event/message.rs | 5 ++- cache/in-memory/src/event/role.rs | 13 ++++-- cache/in-memory/src/event/voice_state.rs | 5 ++- cache/in-memory/src/lib.rs | 10 ++++- .../command/set_command_permissions.rs | 4 +- .../request/channel/invite/create_invite.rs | 6 ++- .../src/request/guild/create_guild/builder.rs | 5 ++- mention/src/parse/iter.rs | 40 +++++++++++++++---- model/src/guild/mod.rs | 5 ++- model/src/template/mod.rs | 8 +++- standby/src/lib.rs | 28 +++++++------ 13 files changed, 120 insertions(+), 48 deletions(-) diff --git a/cache/in-memory/src/event/interaction.rs b/cache/in-memory/src/event/interaction.rs index 9cc81eb648b..06f107a4746 100644 --- a/cache/in-memory/src/event/interaction.rs +++ b/cache/in-memory/src/event/interaction.rs @@ -255,13 +255,18 @@ mod tests { ))); { - let guild_members = cache.guild_members(Id::new_checked(3).expect("non zero")).unwrap(); + let guild_members = cache + .guild_members(Id::new_checked(3).expect("non zero")) + .unwrap(); assert_eq!(guild_members.len(), 2); } { let member = cache - .member(Id::new_checked(3).expect("non zero"), Id::new_checked(6).expect("non zero")) + .member( + Id::new_checked(3).expect("non zero"), + Id::new_checked(6).expect("non zero"), + ) .unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "avatar string"); @@ -269,14 +274,19 @@ mod tests { { let member = cache - .member(Id::new_checked(3).expect("non zero"), Id::new_checked(7).expect("non zero")) + .member( + Id::new_checked(3).expect("non zero"), + Id::new_checked(7).expect("non zero"), + ) .unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "different avatar"); } { - let guild_roles = cache.guild_roles(Id::new_checked(3).expect("non zero")).unwrap(); + let guild_roles = cache + .guild_roles(Id::new_checked(3).expect("non zero")) + .unwrap(); assert_eq!(guild_roles.len(), 1); } } diff --git a/cache/in-memory/src/event/member.rs b/cache/in-memory/src/event/member.rs index 37180da0283..f28b1ffa78a 100644 --- a/cache/in-memory/src/event/member.rs +++ b/cache/in-memory/src/event/member.rs @@ -232,14 +232,16 @@ mod tests { } // Check for the cached guild members ids - let cached_roles = cache.guild_members(Id::new_checked(1).expect("non zero")).unwrap(); + let cached_roles = cache + .guild_members(Id::new_checked(1).expect("non zero")) + .unwrap(); assert_eq!(cached_roles.len(), guild_1_user_ids.len()); assert!(guild_1_user_ids.iter().all(|id| cached_roles.contains(id))); // Check for the cached members - assert!(guild_1_user_ids - .iter() - .all(|id| cache.member(Id::new_checked(1).expect("non zero"), *id).is_some())); + assert!(guild_1_user_ids.iter().all(|id| cache + .member(Id::new_checked(1).expect("non zero"), *id) + .is_some())); // Check for the cached users assert!(guild_1_user_ids.iter().all(|id| cache.user(*id).is_some())); @@ -258,15 +260,16 @@ mod tests { cache.cache_members(Id::new_checked(2).expect("non zero"), guild_2_members); // Check for the cached guild members ids - let cached_roles = cache.guild_members(Id::new_checked(1).expect("non zero")).unwrap(); + let cached_roles = cache + .guild_members(Id::new_checked(1).expect("non zero")) + .unwrap(); assert_eq!(cached_roles.len(), guild_2_user_ids.len()); assert!(guild_2_user_ids.iter().all(|id| cached_roles.contains(id))); // Check for the cached members - assert!(guild_2_user_ids - .iter() - .copied() - .all(|id| cache.member(Id::new_checked(1).expect("non zero"), id).is_some())); + assert!(guild_2_user_ids.iter().copied().all(|id| cache + .member(Id::new_checked(1).expect("non zero"), id) + .is_some())); // Check for the cached users assert!(guild_2_user_ids.iter().all(|id| cache.user(*id).is_some())); diff --git a/cache/in-memory/src/event/message.rs b/cache/in-memory/src/event/message.rs index c5939a0d3fb..129d80ac3c5 100644 --- a/cache/in-memory/src/event/message.rs +++ b/cache/in-memory/src/event/message.rs @@ -218,7 +218,10 @@ mod tests { } assert_eq!( cache - .member(Id::new_checked(1).expect("non zero"), Id::new_checked(3).expect("non zero")) + .member( + Id::new_checked(1).expect("non zero"), + Id::new_checked(3).expect("non zero") + ) .unwrap() .user_id, Id::new_checked(3).expect("non zero"), diff --git a/cache/in-memory/src/event/role.rs b/cache/in-memory/src/event/role.rs index b72ffd27428..bee93a7b20d 100644 --- a/cache/in-memory/src/event/role.rs +++ b/cache/in-memory/src/event/role.rs @@ -96,7 +96,10 @@ mod tests { assert_eq!( "test".to_string(), - cache.role(Id::new_checked(2).expect("non zero")).unwrap().name + cache + .role(Id::new_checked(2).expect("non zero")) + .unwrap() + .name ); } } @@ -123,7 +126,9 @@ mod tests { } // Check for the cached guild role ids - let cached_roles = cache.guild_roles(Id::new_checked(1).expect("non zero")).unwrap(); + let cached_roles = cache + .guild_roles(Id::new_checked(1).expect("non zero")) + .unwrap(); assert_eq!(cached_roles.len(), guild_1_role_ids.len()); assert!(guild_1_role_ids.iter().all(|id| cached_roles.contains(id))); @@ -151,7 +156,9 @@ mod tests { cache.cache_roles(Id::new_checked(2).expect("non zero"), guild_2_roles.clone()); // Check for the cached guild role ids - let cached_roles = cache.guild_roles(Id::new_checked(2).expect("non zero")).unwrap(); + let cached_roles = cache + .guild_roles(Id::new_checked(2).expect("non zero")) + .unwrap(); assert_eq!(cached_roles.len(), guild_2_role_ids.len()); assert!(guild_2_role_ids.iter().all(|id| cached_roles.contains(id))); diff --git a/cache/in-memory/src/event/voice_state.rs b/cache/in-memory/src/event/voice_state.rs index 3ff2810bee9..b47c7608873 100644 --- a/cache/in-memory/src/event/voice_state.rs +++ b/cache/in-memory/src/event/voice_state.rs @@ -384,7 +384,10 @@ mod tests { } assert_eq!( cache - .member(Id::new_checked(2).expect("non zero"), Id::new_checked(3).expect("non zero")) + .member( + Id::new_checked(2).expect("non zero"), + Id::new_checked(3).expect("non zero") + ) .unwrap() .user_id, Id::new_checked(3).expect("non zero"), diff --git a/cache/in-memory/src/lib.rs b/cache/in-memory/src/lib.rs index be34918f2be..f22e863e62d 100644 --- a/cache/in-memory/src/lib.rs +++ b/cache/in-memory/src/lib.rs @@ -950,7 +950,10 @@ mod tests { ); cache.cache_member( Id::new_checked(2).expect("non zero"), - test::member(Id::new_checked(4).expect("non zero"), Id::new_checked(2).expect("non zero")), + test::member( + Id::new_checked(4).expect("non zero"), + Id::new_checked(2).expect("non zero"), + ), ); cache.clear(); assert!(cache.emojis.is_empty()); @@ -975,7 +978,10 @@ mod tests { nick: None, pending: false, premium_since: None, - roles: vec![Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")], + roles: vec![ + Id::new_checked(1).expect("non zero"), + Id::new_checked(2).expect("non zero"), + ], user, }, ); diff --git a/http/src/request/application/command/set_command_permissions.rs b/http/src/request/application/command/set_command_permissions.rs index 98caf78ee73..bd6af4f4ce4 100644 --- a/http/src/request/application/command/set_command_permissions.rs +++ b/http/src/request/application/command/set_command_permissions.rs @@ -361,7 +361,9 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = (1..=SIZE) - .flat_map(|id| command_permissions(Id::new_checked(id as u64).expect("non zero")).take(3)) + .flat_map(|id| { + command_permissions(Id::new_checked(id as u64).expect("non zero")).take(3) + }) .collect::>(); let request = diff --git a/http/src/request/channel/invite/create_invite.rs b/http/src/request/channel/invite/create_invite.rs index 6d8c11d78d0..0f216078226 100644 --- a/http/src/request/channel/invite/create_invite.rs +++ b/http/src/request/channel/invite/create_invite.rs @@ -258,7 +258,8 @@ mod tests { #[test] fn test_max_age() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_age(0)?; + let mut builder = + CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_age(0)?; assert_eq!(Some(0), builder.fields.max_age); builder = builder.max_age(604_800)?; assert_eq!(Some(604_800), builder.fields.max_age); @@ -270,7 +271,8 @@ mod tests { #[test] fn test_max_uses() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_uses(0)?; + let mut builder = + CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_uses(0)?; assert_eq!(Some(0), builder.fields.max_uses); builder = builder.max_uses(100)?; assert_eq!(Some(100), builder.fields.max_uses); diff --git a/http/src/request/guild/create_guild/builder.rs b/http/src/request/guild/create_guild/builder.rs index e4295b19702..8e5feac6d5a 100644 --- a/http/src/request/guild/create_guild/builder.rs +++ b/http/src/request/guild/create_guild/builder.rs @@ -717,7 +717,10 @@ impl GuildChannelFieldsBuilder { .iter() .rev() .find(|c| matches!(c, GuildChannelFields::Category(_))) - .map_or(Id::new_checked(1).expect("non zero"), GuildChannelFields::id); + .map_or( + Id::new_checked(1).expect("non zero"), + GuildChannelFields::id, + ); let mut channels = channel.build(Id::new_checked(last_id.get() + 1).expect("non zero")); diff --git a/mention/src/parse/iter.rs b/mention/src/parse/iter.rs index b1216cc6685..cadcdc1c746 100644 --- a/mention/src/parse/iter.rs +++ b/mention/src/parse/iter.rs @@ -128,7 +128,10 @@ mod tests { #[test] fn test_iter_channel_id() { let mut iter = Id::::iter("<#123>"); - assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!( + Id::new_checked(123).expect("non zero"), + iter.next().unwrap().0 + ); assert!(iter.next().is_none()); } @@ -136,7 +139,10 @@ mod tests { fn test_iter_multiple_ids() { let buf = "one <@123>two<#456><@789> ----"; let mut iter = Id::::iter(buf); - assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); + assert_eq!( + Id::new_checked(123).expect("non zero"), + iter.next().unwrap().0 + ); let (mention, start, end) = iter.next().unwrap(); assert_eq!(Id::new_checked(789).expect("non zero"), mention); assert_eq!(19, start); @@ -147,8 +153,14 @@ mod tests { #[test] fn test_iter_emoji_ids() { let mut iter = Id::::iter("some <:name:123> emojis <:emoji:456>"); - assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!( + Id::new_checked(123).expect("non zero"), + iter.next().unwrap().0 + ); + assert_eq!( + Id::new_checked(456).expect("non zero"), + iter.next().unwrap().0 + ); assert!(iter.next().is_none()); } @@ -199,8 +211,14 @@ mod tests { #[test] fn test_iter_role_ids() { let mut iter = Id::::iter("some <@&123> roles <@&456>"); - assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!( + Id::new_checked(123).expect("non zero"), + iter.next().unwrap().0 + ); + assert_eq!( + Id::new_checked(456).expect("non zero"), + iter.next().unwrap().0 + ); assert!(iter.next().is_none()); } @@ -218,8 +236,14 @@ mod tests { #[test] fn test_iter_user_ids() { let mut iter = Id::::iter("some <@123>users<@456>"); - assert_eq!(Id::new_checked(123).expect("non zero"), iter.next().unwrap().0); - assert_eq!(Id::new_checked(456).expect("non zero"), iter.next().unwrap().0); + assert_eq!( + Id::new_checked(123).expect("non zero"), + iter.next().unwrap().0 + ); + assert_eq!( + Id::new_checked(456).expect("non zero"), + iter.next().unwrap().0 + ); assert!(iter.next().is_none()); } diff --git a/model/src/guild/mod.rs b/model/src/guild/mod.rs index 23db5f2cd4f..11ec66cba6e 100644 --- a/model/src/guild/mod.rs +++ b/model/src/guild/mod.rs @@ -504,8 +504,9 @@ impl<'de> Deserialize<'de> for Guild { return Err(DeError::duplicate_field("presences")); } - let deserializer = - PresenceListDeserializer::new(Id::new_checked(1).expect("non zero")); + let deserializer = PresenceListDeserializer::new( + Id::new_checked(1).expect("non zero"), + ); presences = Some(map.next_value_seed(deserializer)?); } diff --git a/model/src/template/mod.rs b/model/src/template/mod.rs index 9416a8ee1fb..2531e27eec4 100644 --- a/model/src/template/mod.rs +++ b/model/src/template/mod.rs @@ -225,12 +225,16 @@ mod tests { PermissionOverwrite { allow: Permissions::from_bits(0).unwrap(), deny: Permissions::from_bits(2048).unwrap(), - kind: PermissionOverwriteType::Role(Id::new_checked(1).expect("non zero")), + kind: PermissionOverwriteType::Role( + Id::new_checked(1).expect("non zero"), + ), }, PermissionOverwrite { allow: Permissions::from_bits(2048).unwrap(), deny: Permissions::from_bits(0).unwrap(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role( + Id::new_checked(2).expect("non zero"), + ), }, ], position: 0, diff --git a/standby/src/lib.rs b/standby/src/lib.rs index e6ba08ed78c..52431ffc07f 100644 --- a/standby/src/lib.rs +++ b/standby/src/lib.rs @@ -1538,10 +1538,10 @@ mod tests { let event = Event::MessageCreate(Box::new(MessageCreate(message))); let standby = Standby::new(); - let wait = standby - .wait_for_message(Id::new_checked(1).expect("non zero"), |message: &MessageCreate| { - message.author.id.get() == 2 - }); + let wait = standby.wait_for_message( + Id::new_checked(1).expect("non zero"), + |message: &MessageCreate| message.author.id.get() == 2, + ); standby.process(&event); assert_eq!(3, wait.await.map(|msg| msg.id.get()).unwrap()); @@ -1553,8 +1553,10 @@ mod tests { #[tokio::test] async fn test_wait_for_message_stream() { let standby = Standby::new(); - let mut stream = standby - .wait_for_message_stream(Id::new_checked(1).expect("non zero"), |_: &MessageCreate| true); + let mut stream = standby.wait_for_message_stream( + Id::new_checked(1).expect("non zero"), + |_: &MessageCreate| true, + ); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); @@ -1572,10 +1574,10 @@ mod tests { let event = Event::ReactionAdd(Box::new(ReactionAdd(reaction()))); let standby = Standby::new(); - let wait = standby - .wait_for_reaction(Id::new_checked(4).expect("non zero"), |reaction: &ReactionAdd| { - reaction.user_id.get() == 3 - }); + let wait = standby.wait_for_reaction( + Id::new_checked(4).expect("non zero"), + |reaction: &ReactionAdd| reaction.user_id.get() == 3, + ); standby.process(&event); @@ -1591,8 +1593,10 @@ mod tests { #[tokio::test] async fn test_wait_for_reaction_stream() { let standby = Standby::new(); - let mut stream = - standby.wait_for_reaction_stream(Id::new_checked(4).expect("non zero"), |_: &ReactionAdd| true); + let mut stream = standby + .wait_for_reaction_stream(Id::new_checked(4).expect("non zero"), |_: &ReactionAdd| { + true + }); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); From 06b5518a1a3fd73f4490d0232c146fa5dff5841f Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:25:51 -0500 Subject: [PATCH 06/13] use id::new Signed-off-by: Zeyla Hellyer --- cache/in-memory/src/event/emoji.rs | 28 ++-- cache/in-memory/src/event/guild.rs | 26 +-- cache/in-memory/src/event/interaction.rs | 48 +++--- cache/in-memory/src/event/member.rs | 59 +++---- cache/in-memory/src/event/message.rs | 22 +-- cache/in-memory/src/event/reaction.rs | 28 ++-- cache/in-memory/src/event/role.rs | 41 ++--- cache/in-memory/src/event/stage_instance.rs | 6 +- cache/in-memory/src/event/voice_state.rs | 96 +++-------- cache/in-memory/src/iter.rs | 12 +- cache/in-memory/src/lib.rs | 38 ++--- cache/in-memory/src/model/emoji.rs | 4 +- cache/in-memory/src/model/member.rs | 6 +- cache/in-memory/src/model/sticker.rs | 16 +- cache/in-memory/src/permission.rs | 16 +- cache/in-memory/src/test.rs | 32 ++-- examples/gateway-request-members/src/main.rs | 12 +- examples/http-allowed-mentions/src/main.rs | 4 +- examples/http-get-message/src/main.rs | 2 +- examples/http-proxy/src/main.rs | 2 +- examples/lavalink-basic-bot/src/main.rs | 2 +- gateway/src/shard/impl.rs | 2 +- .../application_command_permissions.rs | 8 +- http/src/client/interaction.rs | 2 +- http/src/client/mod.rs | 86 +++++----- http/src/request/application/command/mod.rs | 8 +- .../command/set_command_permissions.rs | 39 ++--- .../interaction/create_followup_message.rs | 8 +- .../interaction/delete_followup_message.rs | 8 +- .../interaction/delete_original_response.rs | 4 +- .../interaction/get_followup_message.rs | 8 +- .../interaction/get_original_response.rs | 4 +- .../interaction/interaction_callback.rs | 4 +- .../interaction/update_followup_message.rs | 12 +- .../interaction/update_original_response.rs | 6 +- http/src/request/channel/get_channel.rs | 2 +- .../request/channel/invite/create_invite.rs | 10 +- .../request/channel/message/create_message.rs | 2 +- .../channel/message/get_channel_messages.rs | 4 +- .../request/channel/message/update_message.rs | 4 +- .../channel/reaction/create_reaction.rs | 8 +- http/src/request/channel/reaction/mod.rs | 6 +- .../request/channel/thread/update_thread.rs | 2 +- .../channel/update_channel_permission.rs | 4 +- .../update_channel_permission_configured.rs | 4 +- .../request/channel/webhook/create_webhook.rs | 2 +- .../channel/webhook/delete_webhook_message.rs | 6 +- .../channel/webhook/execute_webhook.rs | 6 +- .../webhook/execute_webhook_and_wait.rs | 2 +- .../channel/webhook/update_webhook_message.rs | 10 +- http/src/request/guild/ban/create_ban.rs | 4 +- http/src/request/guild/ban/delete_ban.rs | 4 +- http/src/request/guild/ban/get_bans.rs | 2 +- .../src/request/guild/create_guild/builder.rs | 51 +++--- http/src/request/guild/emoji/get_emoji.rs | 4 +- http/src/request/guild/emoji/get_emojis.rs | 2 +- http/src/request/guild/get_audit_log.rs | 2 +- .../request/guild/get_guild_prune_count.rs | 2 +- .../guild/member/add_role_to_member.rs | 6 +- .../request/guild/member/get_guild_members.rs | 4 +- .../guild/member/search_guild_members.rs | 2 +- .../guild/member/update_guild_member.rs | 4 +- http/src/request/guild/role/create_role.rs | 2 +- .../guild/sticker/create_guild_sticker.rs | 2 +- .../guild/sticker/delete_guild_sticker.rs | 4 +- .../guild/sticker/get_guild_sticker.rs | 4 +- .../guild/sticker/get_guild_stickers.rs | 2 +- .../guild/sticker/update_guild_sticker.rs | 4 +- http/src/request/sticker/get_sticker.rs | 2 +- http/src/request/try_into_request.rs | 4 +- .../request/user/get_current_user_guilds.rs | 4 +- http/src/response/future.rs | 4 +- http/src/response/mod.rs | 26 +-- http/src/routing/route_display.rs | 14 +- lavalink/src/player.rs | 4 +- mention/README.md | 2 +- mention/benches/fmt.rs | 16 +- mention/src/fmt.rs | 30 +--- mention/src/lib.rs | 2 +- mention/src/parse/impl.rs | 29 ++-- mention/src/parse/iter.rs | 30 ++-- mention/src/parse/mod.rs | 10 +- model/src/application/command/option.rs | 8 +- model/src/application/command/permissions.rs | 2 +- .../application_command/data/mod.rs | 4 +- .../application_command/data/resolved.rs | 26 +-- .../interaction/message_component/mod.rs | 16 +- model/src/application/interaction/mod.rs | 20 +-- model/src/channel/attachment.rs | 2 +- model/src/channel/category_channel.rs | 4 +- model/src/channel/channel_mention.rs | 4 +- model/src/channel/followed_channel.rs | 4 +- model/src/channel/group.rs | 16 +- .../message/allowed_mentions/builder.rs | 12 +- .../channel/message/allowed_mentions/mod.rs | 4 +- model/src/channel/message/application.rs | 2 +- model/src/channel/message/mention.rs | 4 +- model/src/channel/message/mod.rs | 32 ++-- model/src/channel/message/reference.rs | 8 +- model/src/channel/message/sticker/message.rs | 2 +- model/src/channel/message/sticker/mod.rs | 10 +- model/src/channel/message/sticker/pack.rs | 12 +- model/src/channel/mod.rs | 134 +++++++-------- model/src/channel/permission_overwrite.rs | 8 +- model/src/channel/private_channel.rs | 4 +- model/src/channel/reaction.rs | 22 +-- model/src/channel/reaction_type.rs | 2 +- model/src/channel/stage_instance/mod.rs | 6 +- model/src/channel/text_channel.rs | 12 +- model/src/channel/thread/member.rs | 4 +- model/src/channel/thread/news.rs | 14 +- model/src/channel/thread/private.rs | 14 +- model/src/channel/thread/public.rs | 14 +- model/src/channel/voice_channel.rs | 10 +- model/src/channel/webhook/mod.rs | 22 +-- model/src/gateway/event/gateway.rs | 4 +- .../gateway/payload/incoming/guild_delete.rs | 6 +- .../gateway/payload/incoming/invite_create.rs | 6 +- .../gateway/payload/incoming/member_add.rs | 4 +- .../gateway/payload/incoming/member_chunk.rs | 44 ++--- .../gateway/payload/incoming/member_update.rs | 4 +- model/src/gateway/payload/incoming/ready.rs | 8 +- .../gateway/payload/incoming/role_delete.rs | 4 +- .../gateway/payload/incoming/role_update.rs | 4 +- .../payload/incoming/thread_members_update.rs | 16 +- .../gateway/payload/incoming/typing_start.rs | 18 +- .../payload/incoming/unavailable_guild.rs | 2 +- .../payload/incoming/voice_state_update.rs | 22 +-- .../payload/incoming/webhooks_update.rs | 4 +- .../payload/outgoing/request_guild_members.rs | 14 +- model/src/gateway/presence/mod.rs | 10 +- model/src/guild/audit_log/change.rs | 2 +- model/src/guild/audit_log/entry.rs | 6 +- model/src/guild/ban.rs | 2 +- model/src/guild/emoji.rs | 10 +- model/src/guild/info.rs | 2 +- model/src/guild/integration.rs | 14 +- model/src/guild/integration_application.rs | 6 +- model/src/guild/member.rs | 8 +- model/src/guild/mod.rs | 21 +-- model/src/guild/partial_guild.rs | 14 +- model/src/guild/partial_member.rs | 2 +- model/src/guild/preview.rs | 4 +- model/src/guild/role.rs | 10 +- model/src/guild/role_tags.rs | 4 +- model/src/guild/unavailable_guild.rs | 2 +- model/src/guild/widget.rs | 2 +- model/src/id/mod.rs | 100 ++++++------ model/src/invite/channel.rs | 2 +- model/src/invite/guild.rs | 8 +- model/src/invite/mod.rs | 18 +- model/src/invite/welcome_screen.rs | 6 +- .../src/oauth/current_application_info/mod.rs | 12 +- model/src/oauth/team/member.rs | 4 +- model/src/oauth/team/mod.rs | 4 +- model/src/template/mod.rs | 28 ++-- model/src/user/current_user.rs | 4 +- model/src/user/current_user_guild.rs | 2 +- model/src/user/mod.rs | 4 +- model/src/user/profile.rs | 2 +- model/src/voice/voice_state.rs | 18 +- standby/README.md | 2 +- standby/src/lib.rs | 154 ++++++++---------- util/src/builder/command.rs | 4 +- util/src/link/webhook.rs | 18 +- util/src/permission_calculator/mod.rs | 52 +++--- validate/src/command.rs | 8 +- 167 files changed, 1027 insertions(+), 1213 deletions(-) diff --git a/cache/in-memory/src/event/emoji.rs b/cache/in-memory/src/event/emoji.rs index 3c7e558d48c..82ed1813ad5 100644 --- a/cache/in-memory/src/event/emoji.rs +++ b/cache/in-memory/src/event/emoji.rs @@ -96,7 +96,7 @@ mod tests { fn user_mod(id: Id) -> Option { if id.get() % 2 == 0 { // Only use user for half - Some(test::user(Id::new_checked(1).expect("non zero"))) + Some(test::user(Id::new(1))) } else { None } @@ -104,9 +104,7 @@ mod tests { // Single inserts { - let guild_1_emoji_ids = (1..=10) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_1_emoji_ids = (1..=10).map(Id::new).collect::>(); let guild_1_emoji = guild_1_emoji_ids .iter() .copied() @@ -114,7 +112,7 @@ mod tests { .collect::>(); for emoji in guild_1_emoji { - cache.cache_emoji(Id::new_checked(1).expect("non zero"), emoji); + cache.cache_emoji(Id::new(1), emoji); } for id in guild_1_emoji_ids.iter().cloned() { @@ -124,7 +122,7 @@ mod tests { // Ensure the emoji has been added to the per-guild lookup map to prevent // issues like #551 from returning - let guild_emojis = cache.guild_emojis(Id::new_checked(1).expect("non zero")); + let guild_emojis = cache.guild_emojis(Id::new(1)); assert!(guild_emojis.is_some()); let guild_emojis = guild_emojis.unwrap(); @@ -134,22 +132,20 @@ mod tests { // Bulk inserts { - let guild_2_emoji_ids = (11..=20) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_2_emoji_ids = (11..=20).map(Id::new).collect::>(); let guild_2_emojis = guild_2_emoji_ids .iter() .copied() .map(|id| test::emoji(id, user_mod(id))) .collect::>(); - cache.cache_emojis(Id::new_checked(2).expect("non zero"), guild_2_emojis); + cache.cache_emojis(Id::new(2), guild_2_emojis); for id in guild_2_emoji_ids.iter().cloned() { let global_emoji = cache.emoji(id); assert!(global_emoji.is_some()); } - let guild_emojis = cache.guild_emojis(Id::new_checked(2).expect("non zero")); + let guild_emojis = cache.guild_emojis(Id::new(2)); assert!(guild_emojis.is_some()); let guild_emojis = guild_emojis.unwrap(); @@ -162,11 +158,11 @@ mod tests { fn test_emoji_removal() { let cache = InMemoryCache::new(); - let guild_id = Id::new_checked(1).expect("non zero"); + let guild_id = Id::new(1); - let emote = test::emoji(Id::new_checked(1).expect("non zero"), None); - let emote_2 = test::emoji(Id::new_checked(2).expect("non zero"), None); - let emote_3 = test::emoji(Id::new_checked(3).expect("non zero"), None); + let emote = test::emoji(Id::new(1), None); + let emote_2 = test::emoji(Id::new(2), None); + let emote_3 = test::emoji(Id::new(3), None); cache.cache_emoji(guild_id, emote.clone()); cache.cache_emoji(guild_id, emote_2.clone()); @@ -193,7 +189,7 @@ mod tests { assert!(cache.emoji(emote.id).is_some()); assert!(cache.emoji(emote_2.id).is_none()); - let emote_4 = test::emoji(Id::new_checked(4).expect("non zero"), None); + let emote_4 = test::emoji(Id::new(4), None); cache.update(&GuildEmojisUpdate { emojis: vec![emote_4.clone()], diff --git a/cache/in-memory/src/event/guild.rs b/cache/in-memory/src/event/guild.rs index f1e017b18e5..ca2f66b0d68 100644 --- a/cache/in-memory/src/event/guild.rs +++ b/cache/in-memory/src/event/guild.rs @@ -234,7 +234,7 @@ mod tests { let timestamp = Timestamp::from_str(DATETIME)?; let channels = Vec::from([GuildChannel::Text(TextChannel { - id: Id::new_checked(111).expect("non zero"), + id: Id::new(111), guild_id: None, kind: ChannelType::GuildText, last_message_id: None, @@ -249,7 +249,7 @@ mod tests { })]); let threads = Vec::from([GuildChannel::PublicThread(PublicThread { - id: Id::new_checked(222).expect("non zero"), + id: Id::new(222), default_auto_archive_duration: None, guild_id: None, kind: ChannelType::GuildPublicThread, @@ -269,16 +269,16 @@ mod tests { }, member: Some(ThreadMember { flags: 0, - id: Some(Id::new_checked(1).expect("non zero")), + id: Some(Id::new(1)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(2).expect("non zero")), + user_id: Some(Id::new(2)), }), })]); let guild = Guild { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), afk_channel_id: None, afk_timeout: 300, application_id: None, @@ -301,7 +301,7 @@ mod tests { name: "this is a guild".to_owned(), nsfw_level: NSFWLevel::AgeRestricted, owner: Some(false), - owner_id: Id::new_checked(456).expect("non zero"), + owner_id: Id::new(456), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-GB".to_owned(), premium_subscription_count: Some(0), @@ -330,11 +330,11 @@ mod tests { cache.cache_guild(guild); let channel = cache - .guild_channel(Id::new_checked(111).expect("non zero")) + .guild_channel(Id::new(111)) .unwrap(); let thread = cache - .guild_channel(Id::new_checked(222).expect("non zero")) + .guild_channel(Id::new(222)) .unwrap(); // The channel was given to the cache without a guild ID, but because @@ -343,14 +343,14 @@ mod tests { // correct value. match channel.resource() { GuildChannel::Text(ref c) => { - assert_eq!(Some(Id::new_checked(123).expect("non zero")), c.guild_id); + assert_eq!(Some(Id::new(123)), c.guild_id); } _ => panic!("{:?}", channel), } match thread.resource() { GuildChannel::PublicThread(ref c) => { - assert_eq!(Some(Id::new_checked(123).expect("non zero")), c.guild_id); + assert_eq!(Some(Id::new(123)), c.guild_id); } _ => panic!("{:?}", channel), } @@ -376,7 +376,7 @@ mod tests { explicit_content_filter: ExplicitContentFilter::None, features: Vec::new(), icon: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), joined_at: None, large: false, max_members: None, @@ -387,7 +387,7 @@ mod tests { mfa_level: MfaLevel::None, name: "test".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new_checked(1).expect("non zero"), + owner_id: Id::new(1), owner: None, permissions: None, preferred_locale: "en_us".to_owned(), @@ -431,7 +431,7 @@ mod tests { mfa_level: guild.mfa_level, name: "test2222".to_owned(), nsfw_level: guild.nsfw_level, - owner_id: Id::new_checked(2).expect("non zero"), + owner_id: Id::new(2), owner: guild.owner, permissions: guild.permissions, preferred_locale: guild.preferred_locale, diff --git a/cache/in-memory/src/event/interaction.rs b/cache/in-memory/src/event/interaction.rs index 06f107a4746..2643904812f 100644 --- a/cache/in-memory/src/event/interaction.rs +++ b/cache/in-memory/src/event/interaction.rs @@ -90,16 +90,16 @@ mod tests { let cache = InMemoryCache::new(); cache.update(&InteractionCreate(Interaction::ApplicationCommand( Box::new(ApplicationCommand { - application_id: Id::new_checked(1).expect("non zero"), - channel_id: Id::new_checked(2).expect("non zero"), + application_id: Id::new(1), + channel_id: Id::new(2), data: CommandData { - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), name: "command name".into(), options: Vec::new(), resolved: Some(CommandInteractionDataResolved { channels: HashMap::new(), members: IntoIterator::into_iter([( - Id::new_checked(7).expect("non zero"), + Id::new(7), InteractionMember { avatar: None, communication_disabled_until: None, @@ -108,12 +108,12 @@ mod tests { pending: false, permissions: Permissions::empty(), premium_since: None, - roles: vec![Id::new_checked(8).expect("non zero")], + roles: vec![Id::new(8)], }, )]) .collect(), messages: IntoIterator::into_iter([( - Id::new_checked(4).expect("non zero"), + Id::new(4), Message { activity: None, application: None, @@ -127,7 +127,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -136,14 +136,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -167,7 +167,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "sticker name".to_owned(), }], referenced_message: None, @@ -179,12 +179,12 @@ mod tests { )]) .collect(), roles: IntoIterator::into_iter([( - Id::new_checked(8).expect("non zero"), + Id::new(8), Role { color: 0u32, hoist: false, icon: None, - id: Id::new_checked(8).expect("non zero"), + id: Id::new(8), managed: false, mentionable: true, name: "role name".into(), @@ -196,7 +196,7 @@ mod tests { )]) .collect(), users: IntoIterator::into_iter([( - Id::new_checked(7).expect("non zero"), + Id::new(7), User { accent_color: None, avatar: Some("different avatar".into()), @@ -205,7 +205,7 @@ mod tests { discriminator: 5678, email: None, flags: None, - id: Id::new_checked(7).expect("non zero"), + id: Id::new(7), locale: None, mfa_enabled: None, name: "different name".into(), @@ -218,8 +218,8 @@ mod tests { .collect(), }), }, - guild_id: Some(Id::new_checked(3).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(3)), + id: Id::new(4), kind: InteractionType::ApplicationCommand, member: Some(PartialMember { avatar: None, @@ -239,7 +239,7 @@ mod tests { discriminator: 1234, email: None, flags: None, - id: Id::new_checked(6).expect("non zero"), + id: Id::new(6), locale: None, mfa_enabled: None, name: "username".into(), @@ -256,7 +256,7 @@ mod tests { { let guild_members = cache - .guild_members(Id::new_checked(3).expect("non zero")) + .guild_members(Id::new(3)) .unwrap(); assert_eq!(guild_members.len(), 2); } @@ -264,8 +264,8 @@ mod tests { { let member = cache .member( - Id::new_checked(3).expect("non zero"), - Id::new_checked(6).expect("non zero"), + Id::new(3), + Id::new(6), ) .unwrap(); let user = cache.user(member.user_id).unwrap(); @@ -275,8 +275,8 @@ mod tests { { let member = cache .member( - Id::new_checked(3).expect("non zero"), - Id::new_checked(7).expect("non zero"), + Id::new(3), + Id::new(7), ) .unwrap(); let user = cache.user(member.user_id).unwrap(); @@ -285,7 +285,7 @@ mod tests { { let guild_roles = cache - .guild_roles(Id::new_checked(3).expect("non zero")) + .guild_roles(Id::new(3)) .unwrap(); assert_eq!(guild_roles.len(), 1); } diff --git a/cache/in-memory/src/event/member.rs b/cache/in-memory/src/event/member.rs index f28b1ffa78a..83cb0908d5d 100644 --- a/cache/in-memory/src/event/member.rs +++ b/cache/in-memory/src/event/member.rs @@ -218,30 +218,26 @@ mod tests { // Single inserts { - let guild_1_user_ids = (1..=10) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_1_user_ids = (1..=10).map(Id::new).collect::>(); let guild_1_members = guild_1_user_ids .iter() .copied() - .map(|id| test::member(id, Id::new_checked(1).expect("non zero"))) + .map(|id| test::member(id, Id::new(1))) .collect::>(); for member in guild_1_members { - cache.cache_member(Id::new_checked(1).expect("non zero"), member); + cache.cache_member(Id::new(1), member); } // Check for the cached guild members ids - let cached_roles = cache - .guild_members(Id::new_checked(1).expect("non zero")) - .unwrap(); + let cached_roles = cache.guild_members(Id::new(1)).unwrap(); assert_eq!(cached_roles.len(), guild_1_user_ids.len()); assert!(guild_1_user_ids.iter().all(|id| cached_roles.contains(id))); // Check for the cached members - assert!(guild_1_user_ids.iter().all(|id| cache - .member(Id::new_checked(1).expect("non zero"), *id) - .is_some())); + assert!(guild_1_user_ids + .iter() + .all(|id| cache.member(Id::new(1), *id).is_some())); // Check for the cached users assert!(guild_1_user_ids.iter().all(|id| cache.user(*id).is_some())); @@ -249,27 +245,24 @@ mod tests { // Bulk inserts { - let guild_2_user_ids = (1..=10) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_2_user_ids = (1..=10).map(Id::new).collect::>(); let guild_2_members = guild_2_user_ids .iter() .copied() - .map(|id| test::member(id, Id::new_checked(2).expect("non zero"))) + .map(|id| test::member(id, Id::new(2))) .collect::>(); - cache.cache_members(Id::new_checked(2).expect("non zero"), guild_2_members); + cache.cache_members(Id::new(2), guild_2_members); // Check for the cached guild members ids - let cached_roles = cache - .guild_members(Id::new_checked(1).expect("non zero")) - .unwrap(); + let cached_roles = cache.guild_members(Id::new(1)).unwrap(); assert_eq!(cached_roles.len(), guild_2_user_ids.len()); assert!(guild_2_user_ids.iter().all(|id| cached_roles.contains(id))); // Check for the cached members - assert!(guild_2_user_ids.iter().copied().all(|id| cache - .member(Id::new_checked(1).expect("non zero"), id) - .is_some())); + assert!(guild_2_user_ids + .iter() + .copied() + .all(|id| cache.member(Id::new(1), id).is_some())); // Check for the cached users assert!(guild_2_user_ids.iter().all(|id| cache.user(*id).is_some())); @@ -278,49 +271,43 @@ mod tests { #[test] fn test_cache_user_guild_state() { - let user_id = Id::new_checked(2).expect("non zero"); + let user_id = Id::new(2); let cache = InMemoryCache::new(); - cache.cache_user( - Cow::Owned(test::user(user_id)), - Some(Id::new_checked(1).expect("non zero")), - ); + cache.cache_user(Cow::Owned(test::user(user_id)), Some(Id::new(1))); // Test the guild's ID is the only one in the user's set of guilds. { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(user_guilds.contains(&Id::new_checked(1).expect("non zero"))); + assert!(user_guilds.contains(&Id::new(1))); assert_eq!(1, user_guilds.len()); } // Test that a second guild will cause 2 in the set. - cache.cache_user( - Cow::Owned(test::user(user_id)), - Some(Id::new_checked(3).expect("non zero")), - ); + cache.cache_user(Cow::Owned(test::user(user_id)), Some(Id::new(3))); { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(user_guilds.contains(&Id::new_checked(3).expect("non zero"))); + assert!(user_guilds.contains(&Id::new(3))); assert_eq!(2, user_guilds.len()); } // Test that removing a user from a guild will cause the ID to be // removed from the set, leaving the other ID. cache.update(&MemberRemove { - guild_id: Id::new_checked(3).expect("non zero"), + guild_id: Id::new(3), user: test::user(user_id), }); { let user_guilds = cache.user_guilds.get(&user_id).unwrap(); - assert!(!user_guilds.contains(&Id::new_checked(3).expect("non zero"))); + assert!(!user_guilds.contains(&Id::new(3))); assert_eq!(1, user_guilds.len()); } // Test that removing the user from its last guild removes the user's // entry. cache.update(&MemberRemove { - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), user: test::user(user_id), }); assert!(!cache.users.contains_key(&user_id)); diff --git a/cache/in-memory/src/event/message.rs b/cache/in-memory/src/event/message.rs index 129d80ac3c5..a48161303e2 100644 --- a/cache/in-memory/src/event/message.rs +++ b/cache/in-memory/src/event/message.rs @@ -159,7 +159,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -168,14 +168,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -206,36 +206,36 @@ mod tests { }; cache.update(&MessageCreate(msg.clone())); - msg.id = Id::new_checked(5).expect("non zero"); + msg.id = Id::new(5); cache.update(&MessageCreate(msg)); { let entry = cache .user_guilds - .get(&Id::new_checked(3).expect("non zero")) + .get(&Id::new(3)) .unwrap(); assert_eq!(entry.value().len(), 1); } assert_eq!( cache .member( - Id::new_checked(1).expect("non zero"), - Id::new_checked(3).expect("non zero") + Id::new(1), + Id::new(3) ) .unwrap() .user_id, - Id::new_checked(3).expect("non zero"), + Id::new(3), ); { let entry = cache .channel_messages - .get(&Id::new_checked(2).expect("non zero")) + .get(&Id::new(2)) .unwrap(); assert_eq!(entry.value().len(), 2); } let mut iter = cache - .channel_messages(Id::new_checked(2).expect("non zero")) + .channel_messages(Id::new(2)) .expect("channel is in cache"); // messages are iterated over in descending order from insertion diff --git a/cache/in-memory/src/event/reaction.rs b/cache/in-memory/src/event/reaction.rs index 400d245b53a..18ed4150bcb 100644 --- a/cache/in-memory/src/event/reaction.rs +++ b/cache/in-memory/src/event/reaction.rs @@ -126,7 +126,7 @@ mod tests { fn test_reaction_add() { let cache = test::cache_with_message_and_reactions(); let msg = cache - .message(Id::new_checked(4).expect("non zero")) + .message(Id::new(4)) .unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -150,18 +150,18 @@ mod tests { fn test_reaction_remove() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemove(Reaction { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: None, - message_id: Id::new_checked(4).expect("non zero"), - user_id: Id::new_checked(5).expect("non zero"), + message_id: Id::new(4), + user_id: Id::new(5), })); let msg = cache - .message(Id::new_checked(4).expect("non zero")) + .message(Id::new(4)) .unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -185,13 +185,13 @@ mod tests { fn test_reaction_remove_all() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemoveAll { - channel_id: Id::new_checked(2).expect("non zero"), - message_id: Id::new_checked(4).expect("non zero"), - guild_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Id::new(2), + message_id: Id::new(4), + guild_id: Some(Id::new(1)), }); let msg = cache - .message(Id::new_checked(4).expect("non zero")) + .message(Id::new(4)) .unwrap(); assert_eq!(msg.reactions.len(), 0); @@ -201,16 +201,16 @@ mod tests { fn test_reaction_remove_emoji() { let cache = test::cache_with_message_and_reactions(); cache.update(&ReactionRemoveEmoji { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Id::new_checked(1).expect("non zero"), - message_id: Id::new_checked(4).expect("non zero"), + guild_id: Id::new(1), + message_id: Id::new(4), }); let msg = cache - .message(Id::new_checked(4).expect("non zero")) + .message(Id::new(4)) .unwrap(); assert_eq!(msg.reactions.len(), 1); diff --git a/cache/in-memory/src/event/role.rs b/cache/in-memory/src/event/role.rs index bee93a7b20d..c775575cfd8 100644 --- a/cache/in-memory/src/event/role.rs +++ b/cache/in-memory/src/event/role.rs @@ -79,28 +79,15 @@ mod tests { let cache = InMemoryCache::new(); cache.update(&RoleCreate { - guild_id: Id::new_checked(1).expect("non zero"), - role: test::role(Id::new_checked(2).expect("non zero")), + guild_id: Id::new(1), + role: test::role(Id::new(2)), }); { - assert_eq!( - 1, - cache - .guild_roles - .get(&Id::new_checked(1).expect("non zero")) - .unwrap() - .len() - ); + assert_eq!(1, cache.guild_roles.get(&Id::new(1)).unwrap().len()); assert_eq!(1, cache.roles.len()); - assert_eq!( - "test".to_string(), - cache - .role(Id::new_checked(2).expect("non zero")) - .unwrap() - .name - ); + assert_eq!("test".to_string(), cache.role(Id::new(2)).unwrap().name); } } @@ -111,9 +98,7 @@ mod tests { // Single inserts { // The role ids for the guild with id 1 - let guild_1_role_ids = (1..=10) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_1_role_ids = (1..=10).map(Id::new).collect::>(); // Map the role ids to a test role let guild_1_roles = guild_1_role_ids .iter() @@ -122,13 +107,11 @@ mod tests { .collect::>(); // Cache all the roles using cache role for role in guild_1_roles.clone() { - cache.cache_role(Id::new_checked(1).expect("non zero"), role); + cache.cache_role(Id::new(1), role); } // Check for the cached guild role ids - let cached_roles = cache - .guild_roles(Id::new_checked(1).expect("non zero")) - .unwrap(); + let cached_roles = cache.guild_roles(Id::new(1)).unwrap(); assert_eq!(cached_roles.len(), guild_1_role_ids.len()); assert!(guild_1_role_ids.iter().all(|id| cached_roles.contains(id))); @@ -143,9 +126,7 @@ mod tests { // Bulk inserts { // The role ids for the guild with id 2 - let guild_2_role_ids = (101..=110) - .map(|n| Id::new_checked(n).expect("non zero")) - .collect::>(); + let guild_2_role_ids = (101..=110).map(Id::new).collect::>(); // Map the role ids to a test role let guild_2_roles = guild_2_role_ids .iter() @@ -153,12 +134,10 @@ mod tests { .map(test::role) .collect::>(); // Cache all the roles using cache roles - cache.cache_roles(Id::new_checked(2).expect("non zero"), guild_2_roles.clone()); + cache.cache_roles(Id::new(2), guild_2_roles.clone()); // Check for the cached guild role ids - let cached_roles = cache - .guild_roles(Id::new_checked(2).expect("non zero")) - .unwrap(); + let cached_roles = cache.guild_roles(Id::new(2)).unwrap(); assert_eq!(cached_roles.len(), guild_2_role_ids.len()); assert!(guild_2_role_ids.iter().all(|id| cached_roles.contains(id))); diff --git a/cache/in-memory/src/event/stage_instance.rs b/cache/in-memory/src/event/stage_instance.rs index d00ab62f186..449d5fe5046 100644 --- a/cache/in-memory/src/event/stage_instance.rs +++ b/cache/in-memory/src/event/stage_instance.rs @@ -84,10 +84,10 @@ mod tests { let cache = InMemoryCache::new(); let stage_instance = StageInstance { - channel_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new(1), discoverable_disabled: true, - guild_id: Id::new_checked(2).expect("non zero"), - id: Id::new_checked(3).expect("non zero"), + guild_id: Id::new(2), + id: Id::new(3), privacy_level: PrivacyLevel::GuildOnly, topic: "topic".into(), }; diff --git a/cache/in-memory/src/event/voice_state.rs b/cache/in-memory/src/event/voice_state.rs index b47c7608873..8241979b26b 100644 --- a/cache/in-memory/src/event/voice_state.rs +++ b/cache/in-memory/src/event/voice_state.rs @@ -112,11 +112,7 @@ mod tests { // User 1 joins guild 1's channel 11 (1 channel, 1 guild) { // Ids for this insert - let (guild_id, channel_id, user_id) = ( - Id::new_checked(1).expect("non zero"), - Id::new_checked(11).expect("non zero"), - Id::new_checked(1).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(1), Id::new(11), Id::new(1)); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); // The new user should show up in the global voice states @@ -136,11 +132,7 @@ mod tests { // User 2 joins guild 2's channel 21 (2 channels, 2 guilds) { // Ids for this insert - let (guild_id, channel_id, user_id) = ( - Id::new_checked(2).expect("non zero"), - Id::new_checked(21).expect("non zero"), - Id::new_checked(2).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(2), Id::new(21), Id::new(2)); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); // The new voice state should show up in the global voice states @@ -160,11 +152,7 @@ mod tests { // User 3 joins guild 1's channel 12 (3 channels, 2 guilds) { // Ids for this insert - let (guild_id, channel_id, user_id) = ( - Id::new_checked(1).expect("non zero"), - Id::new_checked(12).expect("non zero"), - Id::new_checked(3).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(1), Id::new(12), Id::new(3)); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); // The new voice state should show up in the global voice states @@ -185,11 +173,7 @@ mod tests { // User 3 moves to guild 1's channel 11 (2 channels, 2 guilds) { // Ids for this insert - let (guild_id, channel_id, user_id) = ( - Id::new_checked(1).expect("non zero"), - Id::new_checked(11).expect("non zero"), - Id::new_checked(3).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(1), Id::new(11), Id::new(3)); cache.cache_voice_state(test::voice_state(guild_id, Some(channel_id), user_id)); // The new voice state should show up in the global voice states @@ -209,11 +193,7 @@ mod tests { // User 3 dcs (2 channels, 2 guilds) { - let (guild_id, channel_id, user_id) = ( - Id::new_checked(1).expect("non zero"), - Id::new_checked(11).expect("non zero"), - Id::new_checked(3).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(1), Id::new(11), Id::new(3)); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); // Now that the user left, they should not show up in the voice states @@ -229,11 +209,7 @@ mod tests { // User 2 dcs (1 channel, 1 guild) { - let (guild_id, channel_id, user_id) = ( - Id::new_checked(2).expect("non zero"), - Id::new_checked(21).expect("non zero"), - Id::new_checked(2).expect("non zero"), - ); + let (guild_id, channel_id, user_id) = (Id::new(2), Id::new(21), Id::new(2)); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); // Now that the user left, they should not show up in the voice states @@ -251,11 +227,8 @@ mod tests { // User 1 dcs (0 channels, 0 guilds) { - let (guild_id, _channel_id, user_id) = ( - Id::new_checked(1).expect("non zero"), - Id::::new_checked(11).expect("non zero"), - Id::new_checked(1).expect("non zero"), - ); + let (guild_id, _channel_id, user_id) = + (Id::new(1), Id::::new(11), Id::new(1)); cache.cache_voice_state(test::voice_state(guild_id, None, user_id)); // Since the last person has disconnected, the global voice states, guilds, and channels should all be gone @@ -268,30 +241,14 @@ mod tests { #[test] fn test_voice_states() { let cache = InMemoryCache::new(); - cache.cache_voice_state(test::voice_state( - Id::new_checked(1).expect("non zero"), - Some(Id::new_checked(2).expect("non zero")), - Id::new_checked(3).expect("non zero"), - )); - cache.cache_voice_state(test::voice_state( - Id::new_checked(1).expect("non zero"), - Some(Id::new_checked(2).expect("non zero")), - Id::new_checked(4).expect("non zero"), - )); + cache.cache_voice_state(test::voice_state(Id::new(1), Some(Id::new(2)), Id::new(3))); + cache.cache_voice_state(test::voice_state(Id::new(1), Some(Id::new(2)), Id::new(4))); // Returns both voice states for the channel that exists. - assert_eq!( - 2, - cache - .voice_channel_states(Id::new_checked(2).expect("non zero")) - .unwrap() - .count() - ); + assert_eq!(2, cache.voice_channel_states(Id::new(2)).unwrap().count()); // Returns None if the channel does not exist. - assert!(cache - .voice_channel_states(Id::new_checked(1).expect("non zero")) - .is_none()); + assert!(cache.voice_channel_states(Id::new(1)).is_none()); } #[test] @@ -303,7 +260,7 @@ mod tests { cache.update(&VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: None, mute: false, self_deaf: false, @@ -312,7 +269,7 @@ mod tests { session_id: "38fj3jfkh3pfho3prh2".to_string(), suppress: false, token: None, - user_id: Id::new_checked(1).expect("non zero"), + user_id: Id::new(1), request_to_speak_timestamp: Some( Timestamp::from_str("2021-04-21T22:16:50+00:00").expect("proper datetime"), ), @@ -327,14 +284,14 @@ mod tests { let cache = InMemoryCache::new(); let mutation = VoiceStateUpdate(VoiceState { - channel_id: Some(Id::new_checked(4).expect("non zero")), + channel_id: Some(Id::new(4)), deaf: false, - guild_id: Some(Id::new_checked(2).expect("non zero")), + guild_id: Some(Id::new(2)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), joined_at, mute: false, nick: None, @@ -349,7 +306,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -366,7 +323,7 @@ mod tests { session_id: "".to_owned(), suppress: false, token: None, - user_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new(3), request_to_speak_timestamp: Some( Timestamp::from_str("2021-04-21T22:16:50+00:00").expect("proper datetime"), ), @@ -376,21 +333,12 @@ mod tests { assert_eq!(cache.members.len(), 1); { - let entry = cache - .user_guilds - .get(&Id::new_checked(3).expect("non zero")) - .unwrap(); + let entry = cache.user_guilds.get(&Id::new(3)).unwrap(); assert_eq!(entry.value().len(), 1); } assert_eq!( - cache - .member( - Id::new_checked(2).expect("non zero"), - Id::new_checked(3).expect("non zero") - ) - .unwrap() - .user_id, - Id::new_checked(3).expect("non zero"), + cache.member(Id::new(2), Id::new(3)).unwrap().user_id, + Id::new(3), ); } } diff --git a/cache/in-memory/src/iter.rs b/cache/in-memory/src/iter.rs index 42d3aca1be0..c0acbe770fd 100644 --- a/cache/in-memory/src/iter.rs +++ b/cache/in-memory/src/iter.rs @@ -115,7 +115,7 @@ impl Deref for IterReference<'_, K, V> { /// let cache = InMemoryCache::new(); /// /// // later in the application... -/// let guild_id = Id::new_checked(1).expect("non zero id"); +/// let guild_id = Id::new(1); /// let maybe_guild_members = cache.guild_members(guild_id); /// /// if let Some(guild_members) = maybe_guild_members { @@ -279,7 +279,7 @@ impl<'a, K: Eq + Hash, V> Iterator for ResourceIter<'a, K, V> { /// use twilight_cache_inmemory::InMemoryCache; /// use twilight_model::id::{ChannelId, MessageId}; /// -/// let channel_id = ChannelId::new_checked(1).expect("non zero id"); +/// let channel_id = ChannelId::new(1); /// /// let cache = InMemoryCache::new(); /// let message_ids = cache.channel_messages(channel_id)?; @@ -349,11 +349,11 @@ mod tests { #[test] fn test_iter() { - let guild_id = Id::new_checked(1).expect("non zero"); + let guild_id = Id::new(1); let users = &[ - (Id::new_checked(2).expect("non zero"), Some(guild_id)), - (Id::new_checked(3).expect("non zero"), Some(guild_id)), - (Id::new_checked(4).expect("non zero"), None), + (Id::new(2), Some(guild_id)), + (Id::new(3), Some(guild_id)), + (Id::new(4), None), ]; let cache = InMemoryCache::new(); diff --git a/cache/in-memory/src/lib.rs b/cache/in-memory/src/lib.rs index f22e863e62d..013f8513b9b 100644 --- a/cache/in-memory/src/lib.rs +++ b/cache/in-memory/src/lib.rs @@ -418,8 +418,8 @@ impl InMemoryCache { /// .resource_types(resource_types) /// .build(); /// - /// let channel_id = Id::new_checked(4).expect("non zero"); - /// let user_id = Id::new_checked(5).expect("non zero"); + /// let channel_id = Id::new(4); + /// let user_id = Id::new(5); /// /// let permissions = cache.permissions().in_channel(user_id, channel_id)?; /// println!("member has these permissions: {:?}", permissions); @@ -936,25 +936,16 @@ mod tests { fn test_syntax_update() { let cache = InMemoryCache::new(); cache.update(&RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(1), }); } #[test] fn test_clear() { let cache = InMemoryCache::new(); - cache.cache_emoji( - Id::new_checked(1).expect("non zero"), - test::emoji(Id::new_checked(3).expect("non zero"), None), - ); - cache.cache_member( - Id::new_checked(2).expect("non zero"), - test::member( - Id::new_checked(4).expect("non zero"), - Id::new_checked(2).expect("non zero"), - ), - ); + cache.cache_emoji(Id::new(1), test::emoji(Id::new(3), None)); + cache.cache_member(Id::new(2), test::member(Id::new(4), Id::new(2))); cache.clear(); assert!(cache.emojis.is_empty()); assert!(cache.members.is_empty()); @@ -964,8 +955,8 @@ mod tests { fn test_highest_role() { let joined_at = Timestamp::from_secs(1_632_072_645).expect("non zero"); let cache = InMemoryCache::new(); - let guild_id = Id::new_checked(1).expect("non zero"); - let user = test::user(Id::new_checked(1).expect("non zero")); + let guild_id = Id::new(1); + let user = test::user(Id::new(1)); cache.cache_member( guild_id, Member { @@ -978,10 +969,7 @@ mod tests { nick: None, pending: false, premium_since: None, - roles: vec![ - Id::new_checked(1).expect("non zero"), - Id::new_checked(2).expect("non zero"), - ], + roles: vec![Id::new(1), Id::new(2)], user, }, ); @@ -993,7 +981,7 @@ mod tests { color: 0, hoist: false, icon: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), managed: false, mentionable: false, name: "test".to_owned(), @@ -1006,7 +994,7 @@ mod tests { color: 0, hoist: false, icon: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), managed: false, mentionable: false, name: "test".to_owned(), @@ -1019,8 +1007,8 @@ mod tests { ); assert_eq!( - cache.member_highest_role(guild_id, Id::new_checked(1).expect("non zero")), - Some(Id::new_checked(2).expect("non zero")) + cache.member_highest_role(guild_id, Id::new(1)), + Some(Id::new(2)) ); } } diff --git a/cache/in-memory/src/model/emoji.rs b/cache/in-memory/src/model/emoji.rs index be29ff0ad79..affe2da0106 100644 --- a/cache/in-memory/src/model/emoji.rs +++ b/cache/in-memory/src/model/emoji.rs @@ -100,7 +100,7 @@ mod tests { #[test] fn test_eq_emoji() { let emoji = Emoji { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), animated: true, name: "foo".to_owned(), managed: false, @@ -110,7 +110,7 @@ mod tests { available: true, }; let cached = CachedEmoji { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), animated: true, name: "foo".to_owned(), managed: false, diff --git a/cache/in-memory/src/model/member.rs b/cache/in-memory/src/model/member.rs index af01c3f090d..d10c3604a09 100644 --- a/cache/in-memory/src/model/member.rs +++ b/cache/in-memory/src/model/member.rs @@ -185,7 +185,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: Some(false), - guild_id: Id::new_checked(3).expect("non zero"), + guild_id: Id::new(3), joined_at, mute: Some(true), nick: Some("member nick".to_owned()), @@ -205,7 +205,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: None, mfa_enabled: None, name: "bar".to_owned(), @@ -224,7 +224,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(3).expect("non zero"), + guild_id: Id::new(3), joined_at, mute: true, nick: Some("member nick".to_owned()), diff --git a/cache/in-memory/src/model/sticker.rs b/cache/in-memory/src/model/sticker.rs index fc577dc76c4..f1298a4188c 100644 --- a/cache/in-memory/src/model/sticker.rs +++ b/cache/in-memory/src/model/sticker.rs @@ -147,11 +147,11 @@ mod tests { available: true, description: Some("sticker".into()), format_type: StickerFormatType::Png, - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(2), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new_checked(3).expect("non zero")), + pack_id: Some(Id::new(3)), sort_value: Some(1), tags: "foo,bar,baz".into(), user: Some(User { @@ -162,7 +162,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), @@ -179,14 +179,14 @@ mod tests { available: true, description: "sticker".into(), format_type: StickerFormatType::Png, - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(2), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new_checked(3).expect("non zero")), + pack_id: Some(Id::new(3)), sort_value: Some(1), tags: "foo,bar,baz".into(), - user_id: Some(Id::new_checked(1).expect("non zero")), + user_id: Some(Id::new(1)), }; assert_eq!(cached, sticker); diff --git a/cache/in-memory/src/permission.rs b/cache/in-memory/src/permission.rs index 9dd07047c65..496883823d6 100644 --- a/cache/in-memory/src/permission.rs +++ b/cache/in-memory/src/permission.rs @@ -280,8 +280,8 @@ impl<'a> InMemoryCachePermissions<'a> { /// /// // later on... /// - /// let channel_id = Id::new_checked(4).expect("non zero"); - /// let user_id = Id::new_checked(5).expect("non zero"); + /// let channel_id = Id::new(4); + /// let user_id = Id::new(5); /// /// let permissions = cache.permissions().in_channel(user_id, channel_id)?; /// println!( @@ -367,8 +367,8 @@ impl<'a> InMemoryCachePermissions<'a> { /// /// // later on... /// - /// let guild_id = Id::new_checked(4).expect("non zero"); - /// let user_id = Id::new_checked(5).expect("non zero"); + /// let guild_id = Id::new(4); + /// let user_id = Id::new(5); /// /// let permissions = cache.permissions().root(user_id, guild_id)?; /// println!( @@ -539,7 +539,7 @@ mod tests { /// Guild ID used in tests. fn guild_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } /// ID of the `@everyone` role. @@ -549,17 +549,17 @@ mod tests { /// User ID used in tests. fn user_id() -> Id { - Id::new_checked(2).expect("non zero") + Id::new(2) } /// ID of another role. fn other_role_id() -> Id { - Id::new_checked(3).expect("non zero") + Id::new(3) } /// ID of the user that owns the guild with the ID [`GUILD_ID`]. fn owner_id() -> Id { - Id::new_checked(4).expect("non zero") + Id::new(4) } /// ID of the #general channel in the guild. diff --git a/cache/in-memory/src/test.rs b/cache/in-memory/src/test.rs index 46b9d23410e..639fcd8bd6f 100644 --- a/cache/in-memory/src/test.rs +++ b/cache/in-memory/src/test.rs @@ -32,7 +32,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -41,14 +41,14 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -81,16 +81,16 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { cache.update(&MessageCreate(msg)); let mut reaction = ReactionAdd(Reaction { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "😀".to_owned(), }, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("member nick".to_owned()), @@ -105,7 +105,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -115,8 +115,8 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { verified: None, }, }), - message_id: Id::new_checked(4).expect("non zero"), - user_id: Id::new_checked(3).expect("non zero"), + message_id: Id::new(4), + user_id: Id::new(3), }); cache.update(&reaction); @@ -125,7 +125,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: None, @@ -140,7 +140,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { discriminator: 2, email: None, flags: None, - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -150,7 +150,7 @@ pub fn cache_with_message_and_reactions() -> InMemoryCache { verified: None, }, }); - reaction.user_id = Id::new_checked(5).expect("non zero"); + reaction.user_id = Id::new(5); cache.update(&reaction); @@ -171,7 +171,7 @@ pub fn current_user(id: u64) -> CurrentUser { bot: true, discriminator: 9876, email: None, - id: Id::new_checked(id).expect("non zero"), + id: Id::new(id), mfa_enabled: true, name: "test".to_owned(), verified: Some(true), @@ -196,8 +196,8 @@ pub fn emoji(id: Id, user: Option) -> Emoji { } pub fn guild_channel_text() -> (Id, Id, GuildChannel) { - let guild_id = Id::new_checked(1).expect("non zero"); - let channel_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let channel_id = Id::new(2); let channel = GuildChannel::Text(TextChannel { guild_id: Some(guild_id), id: channel_id, diff --git a/examples/gateway-request-members/src/main.rs b/examples/gateway-request-members/src/main.rs index 0e2560ec1d7..d1345070364 100644 --- a/examples/gateway-request-members/src/main.rs +++ b/examples/gateway-request-members/src/main.rs @@ -30,20 +30,20 @@ async fn main() -> Result<(), Box> { // Additionally, you can pass in a "nonce" and get it back in // the received member chunk. This can be used to help identify // which request the member is from. - let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new(1)) .nonce("requesting a single member") - .user_id(Id::new_checked(2).expect("non zero")); + .user_id(Id::new(2)); shard.command(&request).await?; // Similarly, you can also request multiple members. Only 100 // members by ID can be requested at a time, so the builder will // check to make sure you're requesting at most that many: - let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new(1)) .nonce("requesting two member") .user_ids(vec![ - Id::new_checked(2).expect("non zero"), - Id::new_checked(3).expect("non zero"), + Id::new(2), + Id::new(3), ]) .unwrap(); @@ -55,7 +55,7 @@ async fn main() -> Result<(), Box> { // number of members to retrieve can be specified. Here we'll // request a list of up to 50 members and their current presence // details whose names start with the letters "tw": - let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + let request = RequestGuildMembers::builder(Id::new(1)) .nonce("querying for members") .presences(true) .query("tw", Some(50)); diff --git a/examples/http-allowed-mentions/src/main.rs b/examples/http-allowed-mentions/src/main.rs index 38c6e3ab8ca..218b9afdbbb 100644 --- a/examples/http-allowed-mentions/src/main.rs +++ b/examples/http-allowed-mentions/src/main.rs @@ -16,8 +16,8 @@ async fn main() -> Result<(), Box> { //add an empty allowed mentions, this will prevent any and all pings .default_allowed_mentions(AllowedMentions::default()) .build(); - let channel_id = Id::new_checked(381_926_291_785_383_946).expect("non zero"); - let user_id = Id::new_checked(77_469_400_222_932_992).expect("non zero"); + let channel_id = Id::new(381_926_291_785_383_946); + let user_id = Id::new(77_469_400_222_932_992); //here we want to warn a user about trying to ping everyone so we override to allow pinging them //but since we did not allow @everyone pings it will not ping everyone diff --git a/examples/http-get-message/src/main.rs b/examples/http-get-message/src/main.rs index ecaea470e2c..414d58948ea 100644 --- a/examples/http-get-message/src/main.rs +++ b/examples/http-get-message/src/main.rs @@ -9,7 +9,7 @@ async fn main() -> Result<(), Box> { tracing_subscriber::fmt::init(); let client = Client::new(env::var("DISCORD_TOKEN")?); - let channel_id = Id::new_checked(381_926_291_785_383_946).expect("non zero"); + let channel_id = Id::new(381_926_291_785_383_946); future::join_all((1u8..=10).map(|x| { client diff --git a/examples/http-proxy/src/main.rs b/examples/http-proxy/src/main.rs index 842f33e0b8e..fc18f3916dd 100644 --- a/examples/http-proxy/src/main.rs +++ b/examples/http-proxy/src/main.rs @@ -12,7 +12,7 @@ async fn main() -> Result<(), Box> { .proxy("localhost:3000".to_owned(), true) .ratelimiter(None) .build(); - let channel_id = Id::new_checked(620_980_184_606_048_278).expect("non zero"); + let channel_id = Id::new(620_980_184_606_048_278); future::join_all((1u8..=10).map(|x| { client diff --git a/examples/lavalink-basic-bot/src/main.rs b/examples/lavalink-basic-bot/src/main.rs index e99884ef615..c6b463f0a0c 100644 --- a/examples/lavalink-basic-bot/src/main.rs +++ b/examples/lavalink-basic-bot/src/main.rs @@ -113,7 +113,7 @@ async fn join(msg: Message, state: State) -> Result<(), Box()?).expect("non zero"); + let channel_id = Id::new(msg.content.parse::()?); let guild_id = msg.guild_id.expect("known to be present"); state diff --git a/gateway/src/shard/impl.rs b/gateway/src/shard/impl.rs index 9b659ec62e9..60e54a7b4cc 100644 --- a/gateway/src/shard/impl.rs +++ b/gateway/src/shard/impl.rs @@ -590,7 +590,7 @@ impl Shard { /// // Query members whose names start with "tw" and limit the results to /// // 10 members. /// let request = - /// RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + /// RequestGuildMembers::builder(Id::new(1)) /// .query("tw", Some(10)); /// /// // Send the request over the shard. diff --git a/http/benches/application_command_permissions.rs b/http/benches/application_command_permissions.rs index 0aa92ced560..efe373d3a81 100644 --- a/http/benches/application_command_permissions.rs +++ b/http/benches/application_command_permissions.rs @@ -10,9 +10,9 @@ fn commands(commands: usize, permissions: usize) -> Vec<(Id, Comm .map(|id| { (0..permissions).map(move |_| { ( - Id::new_checked(id as u64).expect("non zero"), + Id::new(id as u64), CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(4)), permission: true, }, ) @@ -24,7 +24,7 @@ fn commands(commands: usize, permissions: usize) -> Vec<(Id, Comm fn criterion_benchmark(c: &mut Criterion) { let client = Client::new(String::new()); - let application_id = Id::new_checked(1).expect("non zero"); + let application_id = Id::new(1); let command_counts = [5usize, 10, 50, 100]; let permission_counts = [2usize, 5, 10]; @@ -39,7 +39,7 @@ fn criterion_benchmark(c: &mut Criterion) { b.iter(|| { assert!(client .interaction(application_id) - .set_command_permissions(Id::new_checked(2).expect("non zero"), &list) + .set_command_permissions(Id::new(2), &list) .is_ok()); }); }); diff --git a/http/src/client/interaction.rs b/http/src/client/interaction.rs index a5b069daf83..96f9852e08e 100644 --- a/http/src/client/interaction.rs +++ b/http/src/client/interaction.rs @@ -40,7 +40,7 @@ use twilight_validate::command::CommandValidationError; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(123).expect("non zero id"); +/// let application_id = Id::new(123); /// /// let interaction_client = client.interaction(application_id); /// diff --git a/http/src/client/mod.rs b/http/src/client/mod.rs index 78b0914d0e8..70253472040 100644 --- a/http/src/client/mod.rs +++ b/http/src/client/mod.rs @@ -290,7 +290,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let guild_id = Id::new_checked(101).expect("non zero"); + /// let guild_id = Id::new(101); /// let audit_log = client /// // not done /// .audit_log(guild_id) @@ -316,7 +316,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let guild_id = Id::new(1); /// /// let bans = client.bans(guild_id).exec().await?; /// # Ok(()) } @@ -348,8 +348,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(100).expect("non zero"); - /// let user_id = Id::new_checked(200).expect("non zero"); + /// let guild_id = Id::new(100); + /// let user_id = Id::new(200); /// client.create_ban(guild_id, user_id) /// .delete_message_days(1)? /// .reason("memes")? @@ -379,8 +379,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(100).expect("non zero"); - /// let user_id = Id::new_checked(200).expect("non zero"); + /// let guild_id = Id::new(100); + /// let user_id = Id::new(200); /// /// client.delete_ban(guild_id, user_id).exec().await?; /// # Ok(()) } @@ -407,7 +407,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new_checked(100).expect("non zero"); + /// let channel_id = Id::new(100); /// # /// let channel = client.channel(channel_id).exec().await?; /// # Ok(()) } @@ -466,8 +466,8 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); - /// let channel_id = Id::new_checked(123).expect("non zero"); - /// let message_id = Id::new_checked(234).expect("non zero"); + /// let channel_id = Id::new(123); + /// let message_id = Id::new(234); /// let limit: u64 = 6; /// /// let messages = client @@ -517,10 +517,10 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let channel_id = Id::new(123); /// let allow = Permissions::VIEW_CHANNEL; /// let deny = Permissions::SEND_MESSAGES; - /// let role_id = Id::new_checked(432).expect("non zero"); + /// let role_id = Id::new(432); /// /// client.update_channel_permission(channel_id, allow, deny) /// .role(role_id) @@ -598,8 +598,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let after = Id::new_checked(300).expect("non zero"); - /// let before = Id::new_checked(400).expect("non zero"); + /// let after = Id::new(300); + /// let before = Id::new(400); /// let guilds = client.current_user_guilds() /// .after(after) /// .before(before) @@ -637,7 +637,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(100).expect("non zero"); + /// let guild_id = Id::new(100); /// /// client.emojis(guild_id).exec().await?; /// # Ok(()) } @@ -660,8 +660,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(50).expect("non zero"); - /// let emoji_id = Id::new_checked(100).expect("non zero"); + /// let guild_id = Id::new(50); + /// let emoji_id = Id::new(100); /// /// client.emoji(guild_id, emoji_id).exec().await?; /// # Ok(()) } @@ -885,8 +885,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(100).expect("non zero"); - /// let user_id = Id::new_checked(3000).expect("non zero"); + /// let guild_id = Id::new(100); + /// let user_id = Id::new(3000); /// let members = client.guild_members(guild_id).after(user_id).exec().await?; /// # Ok(()) } /// ``` @@ -917,7 +917,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(100).expect("non zero"); + /// let guild_id = Id::new(100); /// let members = client.search_guild_members(guild_id, "Wumpus") /// .limit(10)? /// .exec() @@ -995,7 +995,7 @@ impl Client { /// /// # #[tokio::main] async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let member = client.update_guild_member(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) + /// let member = client.update_guild_member(Id::new(1), Id::new(2)) /// .mute(true) /// .nick(Some("pinkie pie"))? /// .exec() @@ -1044,9 +1044,9 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let guild_id = Id::new_checked(1).expect("non zero"); - /// let role_id = Id::new_checked(2).expect("non zero"); - /// let user_id = Id::new_checked(3).expect("non zero"); + /// let guild_id = Id::new(1); + /// let role_id = Id::new(2); + /// let user_id = Id::new(3); /// /// client.add_guild_member_role(guild_id, user_id, role_id) /// .reason("test")? @@ -1174,7 +1174,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let channel_id = Id::new(123); /// let invite = client /// .create_invite(channel_id) /// .max_uses(3)? @@ -1220,7 +1220,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let channel_id = Id::new(123); /// let message = client /// .create_message(channel_id) /// .content("Twilight is best pony")? @@ -1288,7 +1288,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); - /// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) + /// client.update_message(Id::new(1), Id::new(2)) /// .content(Some("test update"))? /// .exec() /// .await?; @@ -1304,7 +1304,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) + /// client.update_message(Id::new(1), Id::new(2)) /// .content(None)? /// .exec() /// .await?; @@ -1378,8 +1378,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// # - /// let channel_id = Id::new_checked(123).expect("non zero"); - /// let message_id = Id::new_checked(456).expect("non zero"); + /// let channel_id = Id::new(123); + /// let message_id = Id::new(456); /// let emoji = RequestReactionType::Unicode { name: "🌃" }; /// /// let reaction = client @@ -1471,7 +1471,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let guild_id = Id::new_checked(234).expect("non zero"); + /// let guild_id = Id::new(234); /// /// client.create_role(guild_id) /// .color(0xd90083) @@ -1845,7 +1845,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let channel_id = Id::new(123); /// /// let webhook = client /// .create_webhook(channel_id, "Twily Bot") @@ -1893,7 +1893,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); - /// let id = Id::new_checked(432).expect("non zero"); + /// let id = Id::new(432); /// # /// let webhook = client /// .execute_webhook(id, "webhook token") @@ -1935,7 +1935,7 @@ impl Client { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) + /// client.update_webhook_message(Id::new(1), "token here", Id::new(2)) /// .content(Some("new message content"))? /// .exec() /// .await?; @@ -1962,7 +1962,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); /// client - /// .delete_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) + /// .delete_webhook_message(Id::new(1), "token here", Id::new(2)) /// .exec() /// .await?; /// # Ok(()) } @@ -1988,7 +1988,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let id = Id::new_checked(123).expect("non zero"); + /// let id = Id::new(123); /// let sticker = client.sticker(id).exec().await?.model().await?; /// /// println!("{:#?}", sticker); @@ -2030,7 +2030,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let guild_id = Id::new(1); /// let stickers = client /// .guild_stickers(guild_id) /// .exec() @@ -2057,8 +2057,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(1).expect("non zero"); - /// let sticker_id = Id::new_checked(2).expect("non zero"); + /// let guild_id = Id::new(1); + /// let sticker_id = Id::new(2); /// let sticker = client /// .guild_sticker(guild_id, sticker_id) /// .exec() @@ -2089,7 +2089,7 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(1).expect("non zero"); + /// let guild_id = Id::new(1); /// let sticker = client /// .create_guild_sticker( /// guild_id, @@ -2129,8 +2129,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(1).expect("non zero"); - /// let sticker_id = Id::new_checked(2).expect("non zero"); + /// let guild_id = Id::new(1); + /// let sticker_id = Id::new(2); /// let sticker = client /// .update_guild_sticker(guild_id, sticker_id) /// .description("new description")? @@ -2162,8 +2162,8 @@ impl Client { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// - /// let guild_id = Id::new_checked(1).expect("non zero"); - /// let sticker_id = Id::new_checked(2).expect("non zero"); + /// let guild_id = Id::new(1); + /// let sticker_id = Id::new(2); /// /// client /// .delete_guild_sticker(guild_id, sticker_id) diff --git a/http/src/request/application/command/mod.rs b/http/src/request/application/command/mod.rs index 9e491a3d1e8..ba10591cf73 100644 --- a/http/src/request/application/command/mod.rs +++ b/http/src/request/application/command/mod.rs @@ -68,11 +68,11 @@ mod tests { #[test] fn test_command_borrowed_from_command() { let command = Command { - application_id: Some(Id::new_checked(1).expect("non zero")), + application_id: Some(Id::new(1)), default_permission: Some(true), description: "command description".to_owned(), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Some(Id::new_checked(3).expect("non zero")), + guild_id: Some(Id::new(2)), + id: Some(Id::new(3)), kind: CommandType::ChatInput, name: "command name".to_owned(), options: Vec::from([CommandOption::Boolean(BaseCommandOptionData { @@ -80,7 +80,7 @@ mod tests { name: "command name".to_owned(), required: true, })]), - version: Id::new_checked(1).expect("non zero"), + version: Id::new(1), }; let _ = CommandBorrowed { diff --git a/http/src/request/application/command/set_command_permissions.rs b/http/src/request/application/command/set_command_permissions.rs index bd6af4f4ce4..8c1c2af957f 100644 --- a/http/src/request/application/command/set_command_permissions.rs +++ b/http/src/request/application/command/set_command_permissions.rs @@ -79,7 +79,7 @@ impl SortedCommand<'_> { fn new() -> Self { Self { count: 0, - id: Id::new_checked(u64::MAX).expect("non zero"), + id: Id::new(u64::MAX), permissions: OptionalCommandPermissions::new(), } } @@ -231,11 +231,11 @@ mod tests { }; fn application_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } fn guild_id() -> Id { - Id::new_checked(2).expect("non zero") + Id::new(2) } #[derive(Debug, Deserialize, Eq, PartialEq)] @@ -250,7 +250,7 @@ mod tests { iter::repeat(( id, CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(4)), permission: true, }, )) @@ -262,23 +262,23 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = &[ ( - Id::new_checked(1).expect("non zero"), + Id::new(1), CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(3).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(3)), permission: true, }, ), ( - Id::new_checked(1).expect("non zero"), + Id::new(1), CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(4)), permission: true, }, ), ( - Id::new_checked(2).expect("non zero"), + Id::new(2), CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(5).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(5)), permission: true, }, ), @@ -293,22 +293,22 @@ mod tests { let expected = &[ GuildCommandPermissionDeserializable { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), permissions: Vec::from([ CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(3).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(3)), permission: true, }, CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(4).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(4)), permission: true, }, ]), }, GuildCommandPermissionDeserializable { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), permissions: Vec::from([CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(5).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(5)), permission: true, }]), }, @@ -322,7 +322,7 @@ mod tests { #[test] fn test_incorrect_validation() { let http = Client::new("token".to_owned()); - let command_permissions = command_permissions(Id::new_checked(2).expect("non zero")) + let command_permissions = command_permissions(Id::new(2)) .take(GUILD_COMMAND_PERMISSION_LIMIT + 1) .collect::>(); @@ -341,8 +341,7 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = (1..=SIZE) .flat_map(|id| { - command_permissions(Id::new_checked(id as u64).expect("non zero")) - .take(GUILD_COMMAND_PERMISSION_LIMIT) + command_permissions(Id::new(id as u64)).take(GUILD_COMMAND_PERMISSION_LIMIT) }) .collect::>(); @@ -361,9 +360,7 @@ mod tests { let http = Client::new("token".to_owned()); let command_permissions = (1..=SIZE) - .flat_map(|id| { - command_permissions(Id::new_checked(id as u64).expect("non zero")).take(3) - }) + .flat_map(|id| command_permissions(Id::new(id as u64)).take(3)) .collect::>(); let request = diff --git a/http/src/request/application/interaction/create_followup_message.rs b/http/src/request/application/interaction/create_followup_message.rs index badecd3e223..ce42d1f9ab1 100644 --- a/http/src/request/application/interaction/create_followup_message.rs +++ b/http/src/request/application/interaction/create_followup_message.rs @@ -53,7 +53,7 @@ pub(crate) struct CreateFollowupMessageFields<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) @@ -213,7 +213,7 @@ impl<'a> CreateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new_checked(1).expect("non zero"); + /// let application_id = Id::new(1); /// /// let message = client /// .interaction(application_id) @@ -239,7 +239,7 @@ impl<'a> CreateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new_checked(1).expect("non zero"); + /// let application_id = Id::new(1); /// /// let message = client /// .interaction(application_id) @@ -336,7 +336,7 @@ mod tests { #[test] fn test_create_followup_message() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); + let application_id = Id::new(1); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/delete_followup_message.rs b/http/src/request/application/interaction/delete_followup_message.rs index 2d51024a81a..82e0dbf1234 100644 --- a/http/src/request/application/interaction/delete_followup_message.rs +++ b/http/src/request/application/interaction/delete_followup_message.rs @@ -21,11 +21,11 @@ use twilight_model::id::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) -/// .delete_followup_message("token here", Id::new_checked(2).expect("non zero")) +/// .delete_followup_message("token here", Id::new(2)) /// .exec() /// .await?; /// # Ok(()) } @@ -96,9 +96,9 @@ mod tests { let builder = DeleteFollowupMessage::new( &client, - Id::new_checked(1).expect("non zero"), + Id::new(1), "token", - Id::new_checked(2).expect("non zero"), + Id::new(2), ); let actual = builder.try_into_request()?; diff --git a/http/src/request/application/interaction/delete_original_response.rs b/http/src/request/application/interaction/delete_original_response.rs index 64fc7cbd79b..2c4470a5d6e 100644 --- a/http/src/request/application/interaction/delete_original_response.rs +++ b/http/src/request/application/interaction/delete_original_response.rs @@ -20,7 +20,7 @@ use twilight_model::id::{marker::ApplicationMarker, Id}; /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) @@ -82,7 +82,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); + let application_id = Id::new(1); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/get_followup_message.rs b/http/src/request/application/interaction/get_followup_message.rs index 23bb3b4dc49..accad6cbeb6 100644 --- a/http/src/request/application/interaction/get_followup_message.rs +++ b/http/src/request/application/interaction/get_followup_message.rs @@ -26,11 +26,11 @@ use twilight_model::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// let response = client /// .interaction(application_id) -/// .followup_message("token here", Id::new_checked(2).expect("non zero")) +/// .followup_message("token here", Id::new(2)) /// .exec() /// .await?; /// # Ok(()) } @@ -106,11 +106,11 @@ mod tests { const TOKEN: &str = "token"; fn application_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } fn message_id() -> Id { - Id::new_checked(2).expect("non zero") + Id::new(2) } let client = Client::new("token".to_owned()); diff --git a/http/src/request/application/interaction/get_original_response.rs b/http/src/request/application/interaction/get_original_response.rs index ad7eb34e90a..d441198eb01 100644 --- a/http/src/request/application/interaction/get_original_response.rs +++ b/http/src/request/application/interaction/get_original_response.rs @@ -23,7 +23,7 @@ use twilight_model::{ /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) @@ -85,7 +85,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); + let application_id = Id::new(1); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/interaction_callback.rs b/http/src/request/application/interaction/interaction_callback.rs index e95eab024fb..11999873af0 100644 --- a/http/src/request/application/interaction/interaction_callback.rs +++ b/http/src/request/application/interaction/interaction_callback.rs @@ -70,8 +70,8 @@ mod tests { #[test] fn test_interaction_callback() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); - let interaction_id = Id::new_checked(2).expect("non zero id"); + let application_id = Id::new(1); + let interaction_id = Id::new(2); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/update_followup_message.rs b/http/src/request/application/interaction/update_followup_message.rs index ebe1ed70e6a..e1f315e5a08 100644 --- a/http/src/request/application/interaction/update_followup_message.rs +++ b/http/src/request/application/interaction/update_followup_message.rs @@ -61,11 +61,11 @@ struct UpdateFollowupMessageFields<'a> { /// }; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) -/// .update_followup_message("token here", Id::new_checked(2).expect("non zero")) +/// .update_followup_message("token here", Id::new(2)) /// // By creating a default set of allowed mentions, no entity can be /// // mentioned. /// .allowed_mentions(AllowedMentions::default()) @@ -201,7 +201,7 @@ impl<'a> UpdateFollowupMessage<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new_checked(1).expect("non zero"); + /// let application_id = Id::new(1); /// /// let embed = EmbedBuilder::new() /// .description("Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.") @@ -211,7 +211,7 @@ impl<'a> UpdateFollowupMessage<'a> { /// /// client /// .interaction(application_id) - /// .update_followup_message("token", Id::new_checked(2).expect("non zero")) + /// .update_followup_message("token", Id::new(2)) /// .embeds(Some(&[embed]))? /// .exec() /// .await?; @@ -339,8 +339,8 @@ mod tests { #[test] fn test_update_followup_message() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); - let message_id = Id::new_checked(2).expect("non zero id"); + let application_id = Id::new(1); + let message_id = Id::new(2); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/application/interaction/update_original_response.rs b/http/src/request/application/interaction/update_original_response.rs index 2133e9d6b09..48ee4a17514 100644 --- a/http/src/request/application/interaction/update_original_response.rs +++ b/http/src/request/application/interaction/update_original_response.rs @@ -58,7 +58,7 @@ struct UpdateOriginalResponseFields<'a> { /// }; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let application_id = Id::new_checked(1).expect("non zero"); +/// let application_id = Id::new(1); /// /// client /// .interaction(application_id) @@ -199,7 +199,7 @@ impl<'a> UpdateOriginalResponse<'a> { /// use twilight_model::id::Id; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let application_id = Id::new_checked(1).expect("non zero"); + /// let application_id = Id::new(1); /// /// let embed = EmbedBuilder::new() /// .description("Powerful, flexible, and scalable ecosystem of Rust libraries for the Discord API.") @@ -335,7 +335,7 @@ mod tests { #[test] fn test_delete_followup_message() -> Result<(), Box> { - let application_id = Id::new_checked(1).expect("non zero id"); + let application_id = Id::new(1); let token = "foo".to_owned().into_boxed_str(); let client = Client::new(String::new()); diff --git a/http/src/request/channel/get_channel.rs b/http/src/request/channel/get_channel.rs index b559b1773e4..d620bf8b5d1 100644 --- a/http/src/request/channel/get_channel.rs +++ b/http/src/request/channel/get_channel.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new_checked(100).expect("non zero"); +/// let channel_id = Id::new(100); /// /// let channel = client.channel(channel_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/channel/invite/create_invite.rs b/http/src/request/channel/invite/create_invite.rs index 0f216078226..c5a56e7e07c 100644 --- a/http/src/request/channel/invite/create_invite.rs +++ b/http/src/request/channel/invite/create_invite.rs @@ -50,7 +50,7 @@ struct CreateInviteFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let channel_id = Id::new(123); /// let invite = client /// .create_invite(channel_id) /// .max_uses(3)? @@ -104,7 +104,7 @@ impl<'a> CreateInvite<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let invite = client.create_invite(Id::new_checked(1).expect("non zero")) + /// let invite = client.create_invite(Id::new(1)) /// .max_age(60 * 60)? /// .exec() /// .await? @@ -140,7 +140,7 @@ impl<'a> CreateInvite<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new(env::var("DISCORD_TOKEN")?); - /// let invite = client.create_invite(Id::new_checked(1).expect("non zero")) + /// let invite = client.create_invite(Id::new(1)) /// .max_uses(5)? /// .exec() /// .await? @@ -259,7 +259,7 @@ mod tests { fn test_max_age() -> Result<(), Box> { let client = Client::new("foo".to_owned()); let mut builder = - CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_age(0)?; + CreateInvite::new(&client, Id::new(1)).max_age(0)?; assert_eq!(Some(0), builder.fields.max_age); builder = builder.max_age(604_800)?; assert_eq!(Some(604_800), builder.fields.max_age); @@ -272,7 +272,7 @@ mod tests { fn test_max_uses() -> Result<(), Box> { let client = Client::new("foo".to_owned()); let mut builder = - CreateInvite::new(&client, Id::new_checked(1).expect("non zero")).max_uses(0)?; + CreateInvite::new(&client, Id::new(1)).max_uses(0)?; assert_eq!(Some(0), builder.fields.max_uses); builder = builder.max_uses(100)?; assert_eq!(Some(100), builder.fields.max_uses); diff --git a/http/src/request/channel/message/create_message.rs b/http/src/request/channel/message/create_message.rs index a42ebc1f5b5..ef357692848 100644 --- a/http/src/request/channel/message/create_message.rs +++ b/http/src/request/channel/message/create_message.rs @@ -61,7 +61,7 @@ pub(crate) struct CreateMessageFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let channel_id = Id::new(123); /// let message = client /// .create_message(channel_id) /// .content("Twilight is best pony")? diff --git a/http/src/request/channel/message/get_channel_messages.rs b/http/src/request/channel/message/get_channel_messages.rs index 3fda57d2397..c4129c119f9 100644 --- a/http/src/request/channel/message/get_channel_messages.rs +++ b/http/src/request/channel/message/get_channel_messages.rs @@ -37,8 +37,8 @@ struct GetChannelMessagesFields { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let channel_id = Id::new_checked(123).expect("non zero"); -/// let message_id = Id::new_checked(234).expect("non zero"); +/// let channel_id = Id::new(123); +/// let message_id = Id::new(234); /// /// let messages = client /// .channel_messages(channel_id) diff --git a/http/src/request/channel/message/update_message.rs b/http/src/request/channel/message/update_message.rs index 7a8f4053bc7..f808c945620 100644 --- a/http/src/request/channel/message/update_message.rs +++ b/http/src/request/channel/message/update_message.rs @@ -56,7 +56,7 @@ struct UpdateMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) +/// client.update_message(Id::new(1), Id::new(2)) /// .content(Some("test update"))? /// .exec() /// .await?; @@ -72,7 +72,7 @@ struct UpdateMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); -/// client.update_message(Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")) +/// client.update_message(Id::new(1), Id::new(2)) /// .content(None)? /// .exec() /// .await?; diff --git a/http/src/request/channel/reaction/create_reaction.rs b/http/src/request/channel/reaction/create_reaction.rs index 94234fa4be1..9449de4764b 100644 --- a/http/src/request/channel/reaction/create_reaction.rs +++ b/http/src/request/channel/reaction/create_reaction.rs @@ -26,8 +26,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new_checked(123).expect("non zero"); -/// let message_id = Id::new_checked(456).expect("non zero"); +/// let channel_id = Id::new(123); +/// let message_id = Id::new(456); /// let emoji = RequestReactionType::Unicode { name: "🌃" }; /// /// let reaction = client @@ -103,8 +103,8 @@ mod tests { let builder = CreateReaction::new( &client, - Id::new_checked(123).expect("non zero"), - Id::new_checked(456).expect("non zero"), + Id::new(123), + Id::new(456), &emoji, ); let actual = builder.try_into_request()?; diff --git a/http/src/request/channel/reaction/mod.rs b/http/src/request/channel/reaction/mod.rs index 54d921b57f4..421e0a9819c 100644 --- a/http/src/request/channel/reaction/mod.rs +++ b/http/src/request/channel/reaction/mod.rs @@ -75,7 +75,7 @@ impl<'a> RequestReactionType<'a> { /// use twilight_model::id::Id; /// /// let reaction = RequestReactionType::Custom { -/// id: Id::new_checked(123).expect("non zero"), +/// id: Id::new(123), /// name: Some("rarity"), /// }; /// @@ -131,7 +131,7 @@ mod tests { #[test] fn test_display_custom_with_name() { let reaction = RequestReactionType::Custom { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), name: Some("foo"), }; @@ -141,7 +141,7 @@ mod tests { #[test] fn test_display_custom_without_name() { let reaction = RequestReactionType::Custom { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), name: None, }; diff --git a/http/src/request/channel/thread/update_thread.rs b/http/src/request/channel/thread/update_thread.rs index 9b05c20eb40..11b51869756 100644 --- a/http/src/request/channel/thread/update_thread.rs +++ b/http/src/request/channel/thread/update_thread.rs @@ -202,7 +202,7 @@ mod tests { #[test] fn test_request() -> Result<(), Box> { let client = Client::new("token".to_string()); - let channel_id = Id::new_checked(123).expect("non zero"); + let channel_id = Id::new(123); let actual = UpdateThread::new(&client, channel_id) .rate_limit_per_user(60)? diff --git a/http/src/request/channel/update_channel_permission.rs b/http/src/request/channel/update_channel_permission.rs index 6f0f3746818..93291748d36 100644 --- a/http/src/request/channel/update_channel_permission.rs +++ b/http/src/request/channel/update_channel_permission.rs @@ -24,10 +24,10 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let channel_id = Id::new(123); /// let allow = Permissions::VIEW_CHANNEL; /// let deny = Permissions::SEND_MESSAGES; -/// let role_id = Id::new_checked(432).expect("non zero"); +/// let role_id = Id::new(432); /// /// client.update_channel_permission(channel_id, allow, deny) /// .role(role_id) diff --git a/http/src/request/channel/update_channel_permission_configured.rs b/http/src/request/channel/update_channel_permission_configured.rs index 9d1b6568b86..a0b170d5db4 100644 --- a/http/src/request/channel/update_channel_permission_configured.rs +++ b/http/src/request/channel/update_channel_permission_configured.rs @@ -116,10 +116,10 @@ mod tests { let client = Client::new("foo".to_owned()); let builder = UpdateChannelPermissionConfigured::new( &client, - Id::new_checked(1).expect("non zero"), + Id::new(1), Permissions::empty(), Permissions::SEND_MESSAGES, - PermissionOverwriteType::Member(Id::new_checked(2).expect("non zero")), + PermissionOverwriteType::Member(Id::new(2)), ); let actual = builder .try_into_request() diff --git a/http/src/request/channel/webhook/create_webhook.rs b/http/src/request/channel/webhook/create_webhook.rs index aabd7c285c3..3726786eac2 100644 --- a/http/src/request/channel/webhook/create_webhook.rs +++ b/http/src/request/channel/webhook/create_webhook.rs @@ -29,7 +29,7 @@ struct CreateWebhookFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let channel_id = Id::new_checked(123).expect("non zero"); +/// let channel_id = Id::new(123); /// /// let webhook = client /// .create_webhook(channel_id, "Twily Bot") diff --git a/http/src/request/channel/webhook/delete_webhook_message.rs b/http/src/request/channel/webhook/delete_webhook_message.rs index 2632cf9922b..697fef99c72 100644 --- a/http/src/request/channel/webhook/delete_webhook_message.rs +++ b/http/src/request/channel/webhook/delete_webhook_message.rs @@ -23,7 +23,7 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); /// client -/// .delete_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) +/// .delete_webhook_message(Id::new(1), "token here", Id::new(2)) /// .reason("reason here")? /// .exec() /// .await?; @@ -118,9 +118,9 @@ mod tests { let client = Client::new("token".to_owned()); let builder = DeleteWebhookMessage::new( &client, - Id::new_checked(1).expect("non zero"), + Id::new(1), "token", - Id::new_checked(2).expect("non zero"), + Id::new(2), ); let actual = builder .try_into_request() diff --git a/http/src/request/channel/webhook/execute_webhook.rs b/http/src/request/channel/webhook/execute_webhook.rs index ad33ca48cfd..64b50dc38a7 100644 --- a/http/src/request/channel/webhook/execute_webhook.rs +++ b/http/src/request/channel/webhook/execute_webhook.rs @@ -56,7 +56,7 @@ pub(crate) struct ExecuteWebhookFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let id = Id::new_checked(432).expect("non zero"); +/// let id = Id::new(432); /// /// client /// .execute_webhook(id, "webhook token") @@ -213,7 +213,7 @@ impl<'a> ExecuteWebhook<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let message = client.execute_webhook(Id::new_checked(1).expect("non zero"), "token here") + /// let message = client.execute_webhook(Id::new(1), "token here") /// .content("some content")? /// .embeds(&[EmbedBuilder::new().title("title").build()?])? /// .wait() @@ -235,7 +235,7 @@ impl<'a> ExecuteWebhook<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); - /// let message = client.execute_webhook(Id::new_checked(1).expect("non zero"), "token here") + /// let message = client.execute_webhook(Id::new(1), "token here") /// .content("some content")? /// .payload_json(br#"{ "content": "other content", "embeds": [ { "title": "title" } ] }"#) /// .wait() diff --git a/http/src/request/channel/webhook/execute_webhook_and_wait.rs b/http/src/request/channel/webhook/execute_webhook_and_wait.rs index 500f3a8c8fa..ee45c171657 100644 --- a/http/src/request/channel/webhook/execute_webhook_and_wait.rs +++ b/http/src/request/channel/webhook/execute_webhook_and_wait.rs @@ -18,7 +18,7 @@ use twilight_model::channel::Message; /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let id = Id::new_checked(432).expect("non zero"); +/// let id = Id::new(432); /// /// let message = client /// .execute_webhook(id, "webhook token") diff --git a/http/src/request/channel/webhook/update_webhook_message.rs b/http/src/request/channel/webhook/update_webhook_message.rs index 9c7f4fc9306..349eccb5d10 100644 --- a/http/src/request/channel/webhook/update_webhook_message.rs +++ b/http/src/request/channel/webhook/update_webhook_message.rs @@ -63,7 +63,7 @@ struct UpdateWebhookMessageFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// # let client = Client::new("token".to_owned()); -/// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token here", Id::new_checked(2).expect("non zero")) +/// client.update_webhook_message(Id::new(1), "token here", Id::new(2)) /// // By creating a default set of allowed mentions, no entity can be /// // mentioned. /// .allowed_mentions(AllowedMentions::default()) @@ -211,7 +211,7 @@ impl<'a> UpdateWebhookMessage<'a> { /// .url("https://twilight.rs") /// .build()?; /// - /// client.update_webhook_message(Id::new_checked(1).expect("non zero"), "token", Id::new_checked(2).expect("non zero")) + /// client.update_webhook_message(Id::new(1), "token", Id::new(2)) /// .embeds(Some(&[embed]))? /// .exec() /// .await?; @@ -373,13 +373,13 @@ mod tests { let client = Client::new("token".to_owned()); let builder = UpdateWebhookMessage::new( &client, - Id::new_checked(1).expect("non zero"), + Id::new(1), "token", - Id::new_checked(2).expect("non zero"), + Id::new(2), ) .content(Some("test")) .expect("'test' content couldn't be set") - .thread_id(Id::new_checked(3).expect("non zero")) + .thread_id(Id::new(3)) .reason("reason") .expect("'reason' is not a valid reason"); let actual = builder diff --git a/http/src/request/guild/ban/create_ban.rs b/http/src/request/guild/ban/create_ban.rs index afc375207bc..6cd95400974 100644 --- a/http/src/request/guild/ban/create_ban.rs +++ b/http/src/request/guild/ban/create_ban.rs @@ -35,8 +35,8 @@ struct CreateBanFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(100).expect("non zero"); -/// let user_id = Id::new_checked(200).expect("non zero"); +/// let guild_id = Id::new(100); +/// let user_id = Id::new(200); /// client.create_ban(guild_id, user_id) /// .delete_message_days(1)? /// .reason("memes")? diff --git a/http/src/request/guild/ban/delete_ban.rs b/http/src/request/guild/ban/delete_ban.rs index 34d0a4c92d7..cf9b464f5b8 100644 --- a/http/src/request/guild/ban/delete_ban.rs +++ b/http/src/request/guild/ban/delete_ban.rs @@ -24,8 +24,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(100).expect("non zero"); -/// let user_id = Id::new_checked(200).expect("non zero"); +/// let guild_id = Id::new(100); +/// let user_id = Id::new(200); /// /// client.delete_ban(guild_id, user_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/ban/get_bans.rs b/http/src/request/guild/ban/get_bans.rs index 63dcdcdf14f..9f48620649c 100644 --- a/http/src/request/guild/ban/get_bans.rs +++ b/http/src/request/guild/ban/get_bans.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let guild_id = Id::new(1); /// /// let bans = client.bans(guild_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/create_guild/builder.rs b/http/src/request/guild/create_guild/builder.rs index 8e5feac6d5a..636b14c4540 100644 --- a/http/src/request/guild/create_guild/builder.rs +++ b/http/src/request/guild/create_guild/builder.rs @@ -84,7 +84,7 @@ impl RoleFieldsBuilder { pub const COLOR_MAXIMUM: u32 = 0xff_ff_ff; fn role_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } /// Create a new default role field builder. @@ -313,7 +313,7 @@ impl TextFieldsBuilder { } Ok(Self(TextFields { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildText, name, nsfw: None, @@ -487,7 +487,7 @@ impl VoiceFieldsBuilder { Ok(Self(VoiceFields { bitrate: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildVoice, name, permission_overwrites: None, @@ -638,7 +638,7 @@ impl CategoryFieldsBuilder { Ok(Self { fields: CategoryFields { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name, kind: ChannelType::GuildCategory, permission_overwrites: None, @@ -717,12 +717,9 @@ impl GuildChannelFieldsBuilder { .iter() .rev() .find(|c| matches!(c, GuildChannelFields::Category(_))) - .map_or( - Id::new_checked(1).expect("non zero"), - GuildChannelFields::id, - ); + .map_or(Id::new(1), GuildChannelFields::id); - let mut channels = channel.build(Id::new_checked(last_id.get() + 1).expect("non zero")); + let mut channels = channel.build(Id::new(last_id.get() + 1)); self.0.append(&mut channels); @@ -778,7 +775,7 @@ mod tests { PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), } } @@ -805,7 +802,7 @@ mod tests { .color(0x12_34_56) .unwrap() .hoist() - .id(Id::new_checked(2).expect("non zero")) + .id(Id::new(2)) .unwrap() .mentionable() .permissions(Permissions::empty()) @@ -816,7 +813,7 @@ mod tests { RoleFields { color: Some(0x12_34_56), hoist: Some(true), - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), mentionable: Some(true), name: String::from("rolename"), permissions: Some(Permissions::empty()), @@ -837,13 +834,13 @@ mod tests { voice(), VoiceFields { bitrate: Some(96_000), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), parent_id: None, user_limit: Some(40), @@ -874,14 +871,14 @@ mod tests { assert_eq!( text(), TextFields { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), permission_overwrites: Some(vec![PermissionOverwrite { allow: perms(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), parent_id: None, rate_limit_per_user: Some(4_000), @@ -912,13 +909,13 @@ mod tests { channels.build(), vec![ GuildChannelFields::Category(CategoryFields { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::GuildCategory, name: String::from("category"), permission_overwrites: None, }), GuildChannelFields::Text(TextFields { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), @@ -927,15 +924,15 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), - parent_id: Some(Id::new_checked(2).expect("non zero")), + parent_id: Some(Id::new(2)), rate_limit_per_user: Some(4_000), topic: Some(String::from("a topic")), }), GuildChannelFields::Voice(VoiceFields { bitrate: Some(96_000), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { @@ -943,9 +940,9 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), - parent_id: Some(Id::new_checked(2).expect("non zero")), + parent_id: Some(Id::new(2)), user_limit: Some(40), }), ] @@ -962,7 +959,7 @@ mod tests { channels.build(), vec![ GuildChannelFields::Text(TextFields { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), @@ -971,7 +968,7 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), parent_id: None, rate_limit_per_user: Some(4_000), @@ -979,7 +976,7 @@ mod tests { }), GuildChannelFields::Voice(VoiceFields { bitrate: Some(96_000), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), permission_overwrites: Some(vec![PermissionOverwrite { @@ -987,7 +984,7 @@ mod tests { | Permissions::SPEAK | Permissions::SEND_TTS_MESSAGES, deny: Permissions::empty(), - kind: PermissionOverwriteType::Role(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(2)), }]), parent_id: None, user_limit: Some(40), diff --git a/http/src/request/guild/emoji/get_emoji.rs b/http/src/request/guild/emoji/get_emoji.rs index 617a8e6d65c..9adc0a4a186 100644 --- a/http/src/request/guild/emoji/get_emoji.rs +++ b/http/src/request/guild/emoji/get_emoji.rs @@ -27,8 +27,8 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(50).expect("non zero"); -/// let emoji_id = Id::new_checked(100).expect("non zero"); +/// let guild_id = Id::new(50); +/// let emoji_id = Id::new(100); /// /// client.emoji(guild_id, emoji_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/emoji/get_emojis.rs b/http/src/request/guild/emoji/get_emojis.rs index 622080c74ff..363a7b2de20 100644 --- a/http/src/request/guild/emoji/get_emojis.rs +++ b/http/src/request/guild/emoji/get_emojis.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(100).expect("non zero"); +/// let guild_id = Id::new(100); /// /// client.emojis(guild_id).exec().await?; /// # Ok(()) } diff --git a/http/src/request/guild/get_audit_log.rs b/http/src/request/guild/get_audit_log.rs index f5c1213ce89..797e29db7e1 100644 --- a/http/src/request/guild/get_audit_log.rs +++ b/http/src/request/guild/get_audit_log.rs @@ -35,7 +35,7 @@ struct GetAuditLogFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("token".to_owned()); /// -/// let guild_id = Id::new_checked(101).expect("non zero"); +/// let guild_id = Id::new(101); /// let audit_log = client /// .audit_log(guild_id) /// .exec() diff --git a/http/src/request/guild/get_guild_prune_count.rs b/http/src/request/guild/get_guild_prune_count.rs index 3e61c378edd..f98116e30e4 100644 --- a/http/src/request/guild/get_guild_prune_count.rs +++ b/http/src/request/guild/get_guild_prune_count.rs @@ -100,7 +100,7 @@ mod test { fn test_days() { fn days_valid(days: u64) -> bool { let client = Client::new("".to_owned()); - let count = GetGuildPruneCount::new(&client, Id::new_checked(1).expect("non zero")); + let count = GetGuildPruneCount::new(&client, Id::new(1)); let days_result = count.days(days); days_result.is_ok() } diff --git a/http/src/request/guild/member/add_role_to_member.rs b/http/src/request/guild/member/add_role_to_member.rs index f3928613e06..dbb31e0fdb1 100644 --- a/http/src/request/guild/member/add_role_to_member.rs +++ b/http/src/request/guild/member/add_role_to_member.rs @@ -24,9 +24,9 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); -/// let role_id = Id::new_checked(2).expect("non zero"); -/// let user_id = Id::new_checked(3).expect("non zero"); +/// let guild_id = Id::new(1); +/// let role_id = Id::new(2); +/// let user_id = Id::new(3); /// /// client.add_guild_member_role(guild_id, user_id, role_id) /// .reason("test")? diff --git a/http/src/request/guild/member/get_guild_members.rs b/http/src/request/guild/member/get_guild_members.rs index b2b2d2c888b..f267701a8bf 100644 --- a/http/src/request/guild/member/get_guild_members.rs +++ b/http/src/request/guild/member/get_guild_members.rs @@ -36,8 +36,8 @@ struct GetGuildMembersFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(100).expect("non zero"); -/// let user_id = Id::new_checked(3000).expect("non zero"); +/// let guild_id = Id::new(100); +/// let user_id = Id::new(3000); /// let members = client.guild_members(guild_id).after(user_id).exec().await?; /// # Ok(()) } /// ``` diff --git a/http/src/request/guild/member/search_guild_members.rs b/http/src/request/guild/member/search_guild_members.rs index 05cdc4f45ec..9e2a4330ca8 100644 --- a/http/src/request/guild/member/search_guild_members.rs +++ b/http/src/request/guild/member/search_guild_members.rs @@ -31,7 +31,7 @@ struct SearchGuildMembersFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(100).expect("non zero"); +/// let guild_id = Id::new(100); /// let members = client.search_guild_members(guild_id, "Wumpus") /// .limit(10)? /// .exec() diff --git a/http/src/request/guild/member/update_guild_member.rs b/http/src/request/guild/member/update_guild_member.rs index d138dadffc9..f963348b4a0 100644 --- a/http/src/request/guild/member/update_guild_member.rs +++ b/http/src/request/guild/member/update_guild_member.rs @@ -204,11 +204,11 @@ mod tests { }; fn guild_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } fn user_id() -> Id { - Id::new_checked(1).expect("non zero") + Id::new(1) } #[test] diff --git a/http/src/request/guild/role/create_role.rs b/http/src/request/guild/role/create_role.rs index fed789fabb5..6a13dccc016 100644 --- a/http/src/request/guild/role/create_role.rs +++ b/http/src/request/guild/role/create_role.rs @@ -40,7 +40,7 @@ struct CreateRoleFields<'a> { /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); -/// let guild_id = Id::new_checked(234).expect("non zero"); +/// let guild_id = Id::new(234); /// /// client.create_role(guild_id) /// .color(0xd90083) diff --git a/http/src/request/guild/sticker/create_guild_sticker.rs b/http/src/request/guild/sticker/create_guild_sticker.rs index 6c8151df0d2..a67b5ef5b2b 100644 --- a/http/src/request/guild/sticker/create_guild_sticker.rs +++ b/http/src/request/guild/sticker/create_guild_sticker.rs @@ -33,7 +33,7 @@ struct CreateGuildStickerFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let guild_id = Id::new(1); /// let sticker = client /// .create_guild_sticker( /// guild_id, diff --git a/http/src/request/guild/sticker/delete_guild_sticker.rs b/http/src/request/guild/sticker/delete_guild_sticker.rs index a7d70ce9334..738a3f7ec83 100644 --- a/http/src/request/guild/sticker/delete_guild_sticker.rs +++ b/http/src/request/guild/sticker/delete_guild_sticker.rs @@ -22,8 +22,8 @@ use twilight_model::id::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); -/// let sticker_id = Id::new_checked(2).expect("non zero"); +/// let guild_id = Id::new(1); +/// let sticker_id = Id::new(2); /// /// client /// .delete_guild_sticker(guild_id, sticker_id) diff --git a/http/src/request/guild/sticker/get_guild_sticker.rs b/http/src/request/guild/sticker/get_guild_sticker.rs index 35c9d4f9eec..f2bb1995a33 100644 --- a/http/src/request/guild/sticker/get_guild_sticker.rs +++ b/http/src/request/guild/sticker/get_guild_sticker.rs @@ -25,8 +25,8 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); -/// let sticker_id = Id::new_checked(2).expect("non zero"); +/// let guild_id = Id::new(1); +/// let sticker_id = Id::new(2); /// let sticker = client /// .guild_sticker(guild_id, sticker_id) /// .exec() diff --git a/http/src/request/guild/sticker/get_guild_stickers.rs b/http/src/request/guild/sticker/get_guild_stickers.rs index bf5834f5562..354ad4014c2 100644 --- a/http/src/request/guild/sticker/get_guild_stickers.rs +++ b/http/src/request/guild/sticker/get_guild_stickers.rs @@ -22,7 +22,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); +/// let guild_id = Id::new(1); /// let stickers = client /// .guild_stickers(guild_id) /// .exec() diff --git a/http/src/request/guild/sticker/update_guild_sticker.rs b/http/src/request/guild/sticker/update_guild_sticker.rs index d7c4a5a3532..bc1ad3ad448 100644 --- a/http/src/request/guild/sticker/update_guild_sticker.rs +++ b/http/src/request/guild/sticker/update_guild_sticker.rs @@ -37,8 +37,8 @@ struct UpdateGuildStickerFields<'a> { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let guild_id = Id::new_checked(1).expect("non zero"); -/// let sticker_id = Id::new_checked(2).expect("non zero"); +/// let guild_id = Id::new(1); +/// let sticker_id = Id::new(2); /// let sticker = client /// .update_guild_sticker(guild_id, sticker_id) /// .description("new description")? diff --git a/http/src/request/sticker/get_sticker.rs b/http/src/request/sticker/get_sticker.rs index fd11b5c9bee..f9fa0b13f2e 100644 --- a/http/src/request/sticker/get_sticker.rs +++ b/http/src/request/sticker/get_sticker.rs @@ -22,7 +22,7 @@ use twilight_model::{ /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let id = Id::new_checked(123).expect("non zero"); +/// let id = Id::new(123); /// let sticker = client.sticker(id).exec().await?.model().await?; /// # Ok(()) } /// ``` diff --git a/http/src/request/try_into_request.rs b/http/src/request/try_into_request.rs index 7e1caff1041..9bac6875293 100644 --- a/http/src/request/try_into_request.rs +++ b/http/src/request/try_into_request.rs @@ -267,7 +267,7 @@ use crate::error::Error; /// use twilight_model::{channel::Message, id::Id}; /// /// let client = Client::new(env::var("DISCORD_TOKEN")?); -/// let channel_id = Id::new_checked(1).expect("non zero"); +/// let channel_id = Id::new(1); /// let builder = client.create_message(channel_id) /// .content("This is a test message!")? /// .tts(false); @@ -321,7 +321,7 @@ mod tests { #[test] fn test_conversion() -> Result<(), Box> { let client = Client::new("token".to_owned()); - let channel_id = Id::new_checked(1).expect("non zero"); + let channel_id = Id::new(1); let builder = client.create_message(channel_id).content("test")?; let request = builder.try_into_request()?; diff --git a/http/src/request/user/get_current_user_guilds.rs b/http/src/request/user/get_current_user_guilds.rs index 9956487b45f..13e58ee215a 100644 --- a/http/src/request/user/get_current_user_guilds.rs +++ b/http/src/request/user/get_current_user_guilds.rs @@ -34,8 +34,8 @@ struct GetCurrentUserGuildsFields { /// # async fn main() -> Result<(), Box> { /// let client = Client::new("my token".to_owned()); /// -/// let after = Id::new_checked(300).expect("non zero"); -/// let before = Id::new_checked(400).expect("non zero"); +/// let after = Id::new(300); +/// let before = Id::new(400); /// let guilds = client.current_user_guilds() /// .after(after) /// .before(before) diff --git a/http/src/response/future.rs b/http/src/response/future.rs index 52f21f7e394..16fee8c8df9 100644 --- a/http/src/response/future.rs +++ b/http/src/response/future.rs @@ -330,8 +330,8 @@ impl ResponseFuture { /// use twilight_http::{error::ErrorType, Client}; /// use twilight_model::id::{ChannelId, MessageId}; /// - /// let channel_id = ChannelId::new_checked(1).expect("non zero id"); - /// let message_id = MessageId::new_checked(2).expect("non zero id"); + /// let channel_id = ChannelId::new(1); + /// let message_id = MessageId::new(2); /// /// let channels_ignored = { /// let mut map = HashSet::new(); diff --git a/http/src/response/mod.rs b/http/src/response/mod.rs index c4af0d2b523..a49dd959a35 100644 --- a/http/src/response/mod.rs +++ b/http/src/response/mod.rs @@ -18,7 +18,7 @@ //! ```no_run //! # #[tokio::main] //! # async fn main() -> Result<(), Box> { -//! # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +//! # let user_id = twilight_model::id::Id::new(1); //! use std::env; //! use twilight_http::Client; //! @@ -165,7 +165,7 @@ pub enum DeserializeBodyErrorType { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let user_id = twilight_model::id::Id::new(1); /// use std::env; /// use twilight_http::Client; /// @@ -221,7 +221,7 @@ impl Response { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { - /// # let user_id = twilight_model::id::Id::new_checked(1).expect("non zero"); + /// # let user_id = twilight_model::id::Id::new(1); /// use std::env; /// use twilight_http::Client; /// @@ -442,7 +442,7 @@ impl Response { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new(1); /// use std::env; /// use twilight_http::Client; /// @@ -495,8 +495,8 @@ impl<'a> Iterator for HeaderIter<'a> { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); -/// # let message_id = twilight_model::id::Id::new_checked(2).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new(1); +/// # let message_id = twilight_model::id::Id::new(2); /// use std::env; /// use twilight_http::Client; /// @@ -541,8 +541,8 @@ impl Future for BytesFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); -/// # let emoji_id = twilight_model::id::Id::new_checked(2).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new(1); +/// # let emoji_id = twilight_model::id::Id::new(2); /// use std::env; /// use twilight_http::Client; /// @@ -603,8 +603,8 @@ impl Future for ModelFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); -/// # let user_id = twilight_model::id::Id::new_checked(2).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new(1); +/// # let user_id = twilight_model::id::Id::new(2); /// use std::env; /// use twilight_http::Client; /// @@ -680,7 +680,7 @@ impl Future for MemberFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let guild_id = twilight_model::id::Id::new_checked(1).expect("non zero"); +/// # let guild_id = twilight_model::id::Id::new(1); /// use std::env; /// use twilight_http::Client; /// @@ -759,8 +759,8 @@ impl Future for MemberListFuture { /// ```no_run /// # #[tokio::main] /// # async fn main() -> Result<(), Box> { -/// # let channel_id = twilight_model::id::Id::new_checked(1).expect("non zero"); -/// # let message_id = twilight_model::id::Id::new_checked(2).expect("non zero"); +/// # let channel_id = twilight_model::id::Id::new(1); +/// # let message_id = twilight_model::id::Id::new(2); /// use std::env; /// use twilight_http::Client; /// diff --git a/http/src/routing/route_display.rs b/http/src/routing/route_display.rs index 1692e3df526..0bb5979c273 100644 --- a/http/src/routing/route_display.rs +++ b/http/src/routing/route_display.rs @@ -1145,7 +1145,7 @@ mod tests { fn emoji() -> RequestReactionType<'static> { RequestReactionType::Custom { - id: Id::new_checked(EMOJI_ID).expect("non zero id"), + id: Id::new(EMOJI_ID), name: None, } } @@ -2922,7 +2922,7 @@ mod tests { #[test] fn test_create_guild_prune_include_one_role() { - let include_roles = [Id::new_checked(1).expect("non zero id")]; + let include_roles = [Id::new(1)]; let route = Route::CreateGuildPrune { compute_prune_count: None, @@ -2941,10 +2941,7 @@ mod tests { #[test] fn test_create_guild_prune_include_two_roles() { - let include_roles = [ - Id::new_checked(1).expect("non zero id"), - Id::new_checked(2).expect("non zero id"), - ]; + let include_roles = [Id::new(1), Id::new(2)]; let route = Route::CreateGuildPrune { compute_prune_count: None, @@ -2963,10 +2960,7 @@ mod tests { #[test] fn test_create_guild_prune_all() { - let include_roles = [ - Id::new_checked(1).expect("non zero id"), - Id::new_checked(2).expect("non zero id"), - ]; + let include_roles = [Id::new(1), Id::new(2)]; let route = Route::CreateGuildPrune { compute_prune_count: Some(true), diff --git a/lavalink/src/player.rs b/lavalink/src/player.rs index 01cef972012..5bca35d380f 100644 --- a/lavalink/src/player.rs +++ b/lavalink/src/player.rs @@ -117,7 +117,7 @@ impl Player { /// use twilight_lavalink::{model::{Play, Pause}, Lavalink}; /// # use twilight_model::id::Id; /// # fn main() -> Result<(), Box> { - /// # let (guild_id, user_id) = (Id::new_checked(1).expect("non zero"), Id::new_checked(2).expect("non zero")); + /// # let (guild_id, user_id) = (Id::new(1), Id::new(2)); /// # let track = String::new(); /// /// let lavalink = Lavalink::new(user_id, 10); @@ -173,7 +173,7 @@ impl Player { if channel_id == 0 { None } else { - Some(Id::new_checked(channel_id).expect("non zero")) + Some(Id::new(channel_id)) } } diff --git a/mention/README.md b/mention/README.md index 98851d8549a..5b4b04497ff 100644 --- a/mention/README.md +++ b/mention/README.md @@ -18,7 +18,7 @@ Create a mention formatter for a user ID, and then format it in a message: use twilight_mention::Mention; use twilight_model::id::{marker::UserMarker, Id}; -let user_id = Id::::new_checked(123).expect("non zero"); +let user_id = Id::::new(123); let message = format!("Hey there, {}!", user_id.mention()); ``` diff --git a/mention/benches/fmt.rs b/mention/benches/fmt.rs index fab61424e74..b34fd8a39cc 100644 --- a/mention/benches/fmt.rs +++ b/mention/benches/fmt.rs @@ -13,33 +13,25 @@ fn format_id(input: &mut String, formatter: &T) { fn criterion_benchmark(c: &mut Criterion) { c.bench_function("format channel id", |b| { let mut string = String::new(); - let formatter = Id::::new_checked(999_999_999_999_999_999) - .expect("non zero") - .mention(); + let formatter = Id::::new(999_999_999_999_999_999).mention(); b.iter(|| format_id(&mut string, &formatter)) }); c.bench_function("format emoji id", |b| { let mut string = String::new(); - let formatter = Id::::new_checked(999_999_999_999_999_999) - .expect("non zero") - .mention(); + let formatter = Id::::new(999_999_999_999_999_999).mention(); b.iter(|| format_id(&mut string, &formatter)) }); c.bench_function("format role id", |b| { let mut string = String::new(); - let formatter = Id::::new_checked(999_999_999_999_999_999) - .expect("non zero") - .mention(); + let formatter = Id::::new(999_999_999_999_999_999).mention(); b.iter(|| format_id(&mut string, &formatter)) }); c.bench_function("format user id", |b| { let mut string = String::new(); - let formatter = Id::::new_checked(999_999_999_999_999_999) - .expect("non zero") - .mention(); + let formatter = Id::::new(999_999_999_999_999_999).mention(); b.iter(|| format_id(&mut string, &formatter)) }); diff --git a/mention/src/fmt.rs b/mention/src/fmt.rs index a24a3e28030..1604eaaff36 100644 --- a/mention/src/fmt.rs +++ b/mention/src/fmt.rs @@ -24,7 +24,7 @@ use twilight_model::{ /// use twilight_mention::Mention; /// use twilight_model::id::{marker::UserMarker, Id}; /// -/// assert_eq!("<@123>", Id::::new_checked(123).expect("non zero").mention().to_string()); +/// assert_eq!("<@123>", Id::::new(123).mention().to_string()); /// ``` #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub struct MentionFormat(T); @@ -99,7 +99,7 @@ impl Display for MentionFormat> { /// use twilight_mention::Mention; /// use twilight_model::id::{marker::ChannelMarker, Id}; /// -/// let id = Id::::new_checked(123).expect("non zero"); +/// let id = Id::::new(123); /// assert_eq!("<#123>", id.mention().to_string()); /// ``` pub trait Mention { @@ -295,10 +295,7 @@ mod tests { fn test_mention_format_channel_id() { assert_eq!( "<#123>", - Id::::new_checked(123) - .expect("non zero") - .mention() - .to_string() + Id::::new(123).mention().to_string() ); } @@ -306,22 +303,13 @@ mod tests { fn test_mention_format_emoji_id() { assert_eq!( "<:emoji:123>", - Id::::new_checked(123) - .expect("non zero") - .mention() - .to_string() + Id::::new(123).mention().to_string() ); } #[test] fn test_mention_format_role_id() { - assert_eq!( - "<@&123>", - Id::::new_checked(123) - .expect("non zero") - .mention() - .to_string() - ); + assert_eq!("<@&123>", Id::::new(123).mention().to_string()); } /// Test that a timestamp with a style displays correctly. @@ -342,12 +330,6 @@ mod tests { #[test] fn test_mention_format_user_id() { - assert_eq!( - "<@123>", - Id::::new_checked(123) - .expect("non zero") - .mention() - .to_string() - ); + assert_eq!("<@123>", Id::::new(123).mention().to_string()); } } diff --git a/mention/src/lib.rs b/mention/src/lib.rs index d4f752b6362..f549afb6544 100644 --- a/mention/src/lib.rs +++ b/mention/src/lib.rs @@ -16,7 +16,7 @@ //! use twilight_mention::Mention; //! use twilight_model::id::{marker::UserMarker, Id}; //! -//! let user_id = Id::::new_checked(123).expect("non zero"); +//! let user_id = Id::::new(123); //! let message = format!("Hey there, {}!", user_id.mention()); //! ``` //! diff --git a/mention/src/parse/impl.rs b/mention/src/parse/impl.rs index a9b55bf415c..f5107d9a63e 100644 --- a/mention/src/parse/impl.rs +++ b/mention/src/parse/impl.rs @@ -35,11 +35,11 @@ pub trait ParseMention: private::Sealed { /// /// # fn main() -> Result<(), Box> { /// assert_eq!( - /// Id::::new_checked(123).expect("non zero"), + /// Id::::new(123), /// Id::parse("<#123>")?, /// ); /// assert_eq!( - /// Id::::new_checked(456).expect("non zero"), + /// Id::::new(456), /// Id::parse("<@456>")?, /// ); /// assert!(Id::::parse("not a mention").is_err()); @@ -387,10 +387,7 @@ mod tests { #[test] fn test_parse_channel_id() { - assert_eq!( - Id::::new_checked(123).expect("non zero"), - Id::parse("<#123>").unwrap() - ); + assert_eq!(Id::::new(123), Id::parse("<#123>").unwrap()); assert_eq!( &ParseMentionErrorType::Sigil { expected: &["#"], @@ -403,7 +400,7 @@ mod tests { #[test] fn test_parse_emoji_id() { assert_eq!( - Id::::new_checked(123).expect("non zero"), + Id::::new(123), Id::parse("<:name:123>").unwrap() ); assert_eq!( @@ -418,19 +415,19 @@ mod tests { #[test] fn test_parse_mention_type() { assert_eq!( - MentionType::Channel(Id::new_checked(123).expect("non zero")), + MentionType::Channel(Id::new(123)), MentionType::parse("<#123>").unwrap() ); assert_eq!( - MentionType::Emoji(Id::new_checked(123).expect("non zero")), + MentionType::Emoji(Id::new(123)), MentionType::parse("<:name:123>").unwrap() ); assert_eq!( - MentionType::Role(Id::new_checked(123).expect("non zero")), + MentionType::Role(Id::new(123)), MentionType::parse("<@&123>").unwrap() ); assert_eq!( - MentionType::User(Id::new_checked(123).expect("non zero")), + MentionType::User(Id::new(123)), MentionType::parse("<@123>").unwrap() ); assert_eq!( @@ -444,10 +441,7 @@ mod tests { #[test] fn test_parse_role_id() { - assert_eq!( - Id::::new_checked(123).expect("non zero"), - Id::parse("<@&123>").unwrap() - ); + assert_eq!(Id::::new(123), Id::parse("<@&123>").unwrap()); assert_eq!( &ParseMentionErrorType::Sigil { expected: &["@&"], @@ -474,10 +468,7 @@ mod tests { #[test] fn test_parse_user_id() { - assert_eq!( - Id::::new_checked(123).expect("non zero"), - Id::parse("<@123>").unwrap() - ); + assert_eq!(Id::::new(123), Id::parse("<@123>").unwrap()); assert_eq!( &ParseMentionErrorType::IdNotU64 { found: "&123" }, Id::::parse("<@&123>").unwrap_err().kind(), diff --git a/mention/src/parse/iter.rs b/mention/src/parse/iter.rs index cadcdc1c746..28e019dd3c2 100644 --- a/mention/src/parse/iter.rs +++ b/mention/src/parse/iter.rs @@ -129,7 +129,7 @@ mod tests { fn test_iter_channel_id() { let mut iter = Id::::iter("<#123>"); assert_eq!( - Id::new_checked(123).expect("non zero"), + Id::new(123), iter.next().unwrap().0 ); assert!(iter.next().is_none()); @@ -140,11 +140,11 @@ mod tests { let buf = "one <@123>two<#456><@789> ----"; let mut iter = Id::::iter(buf); assert_eq!( - Id::new_checked(123).expect("non zero"), + Id::new(123), iter.next().unwrap().0 ); let (mention, start, end) = iter.next().unwrap(); - assert_eq!(Id::new_checked(789).expect("non zero"), mention); + assert_eq!(Id::new(789), mention); assert_eq!(19, start); assert_eq!(24, end); assert!(iter.next().is_none()); @@ -154,11 +154,11 @@ mod tests { fn test_iter_emoji_ids() { let mut iter = Id::::iter("some <:name:123> emojis <:emoji:456>"); assert_eq!( - Id::new_checked(123).expect("non zero"), + Id::new(123), iter.next().unwrap().0 ); assert_eq!( - Id::new_checked(456).expect("non zero"), + Id::new(456), iter.next().unwrap().0 ); assert!(iter.next().is_none()); @@ -168,23 +168,23 @@ mod tests { fn test_iter_mention_type() { let mut iter = MentionType::iter("<#12><:name:34><@&56><@!78><@90>"); assert_eq!( - MentionType::Channel(Id::new_checked(12).expect("non zero")), + MentionType::Channel(Id::new(12)), iter.next().unwrap().0 ); assert_eq!( - MentionType::Emoji(Id::new_checked(34).expect("non zero")), + MentionType::Emoji(Id::new(34)), iter.next().unwrap().0 ); assert_eq!( - MentionType::Role(Id::new_checked(56).expect("non zero")), + MentionType::Role(Id::new(56)), iter.next().unwrap().0 ); assert_eq!( - MentionType::User(Id::new_checked(78).expect("non zero")), + MentionType::User(Id::new(78)), iter.next().unwrap().0 ); assert_eq!( - MentionType::User(Id::new_checked(90).expect("non zero")), + MentionType::User(Id::new(90)), iter.next().unwrap().0 ); assert!(iter.next().is_none()); @@ -194,7 +194,7 @@ mod tests { fn test_iter_mention_type_with_timestamp() { let mut iter = MentionType::iter("<#12> "); assert_eq!( - MentionType::Channel(Id::new_checked(12).expect("non zero")), + MentionType::Channel(Id::new(12)), iter.next().unwrap().0 ); assert_eq!( @@ -212,11 +212,11 @@ mod tests { fn test_iter_role_ids() { let mut iter = Id::::iter("some <@&123> roles <@&456>"); assert_eq!( - Id::new_checked(123).expect("non zero"), + Id::new(123), iter.next().unwrap().0 ); assert_eq!( - Id::new_checked(456).expect("non zero"), + Id::new(456), iter.next().unwrap().0 ); assert!(iter.next().is_none()); @@ -237,11 +237,11 @@ mod tests { fn test_iter_user_ids() { let mut iter = Id::::iter("some <@123>users<@456>"); assert_eq!( - Id::new_checked(123).expect("non zero"), + Id::new(123), iter.next().unwrap().0 ); assert_eq!( - Id::new_checked(456).expect("non zero"), + Id::new(456), iter.next().unwrap().0 ); assert!(iter.next().is_none()); diff --git a/mention/src/parse/mod.rs b/mention/src/parse/mod.rs index 2ac2997b933..b0d6f76086b 100644 --- a/mention/src/parse/mod.rs +++ b/mention/src/parse/mod.rs @@ -22,8 +22,8 @@ //! }; //! //! # fn main() -> Result<(), Box> { -//! assert_eq!(Id::::new_checked(123).expect("non zero"), Id::parse("<:name:123>")?); -//! assert_eq!(Id::::new_checked(456).expect("non zero"), Id::parse("<@&456>")?); +//! assert_eq!(Id::::new(123), Id::parse("<:name:123>")?); +//! assert_eq!(Id::::new(456), Id::parse("<@&456>")?); //! assert!(Id::::parse("<#notamention>").is_err()); //! # Ok(()) } //! ``` @@ -98,15 +98,15 @@ use twilight_model::id::{ /// /// # fn main() -> Result<(), Box> { /// assert_eq!( -/// MentionType::Channel(Id::::new_checked(123).expect("non zero")), +/// MentionType::Channel(Id::::new(123)), /// MentionType::parse("<#123>")?, /// ); /// assert_eq!( -/// MentionType::Role(Id::::new_checked(123).expect("non zero")), +/// MentionType::Role(Id::::new(123)), /// MentionType::parse("<@&123>")?, /// ); /// assert_eq!( -/// MentionType::User(Id::::new_checked(123).expect("non zero")), +/// MentionType::User(Id::::new(123)), /// MentionType::parse("<@!123>")?, /// ); /// diff --git a/model/src/application/command/option.rs b/model/src/application/command/option.rs index 3ae8f926320..725521b4344 100644 --- a/model/src/application/command/option.rs +++ b/model/src/application/command/option.rs @@ -672,11 +672,11 @@ mod tests { #[allow(clippy::too_many_lines)] fn test_command_option_full() { let value = Command { - application_id: Some(Id::new_checked(100).expect("non zero")), + application_id: Some(Id::new(100)), default_permission: Some(true), description: "this command is a test".into(), - guild_id: Some(Id::new_checked(300).expect("non zero")), - id: Some(Id::new_checked(200).expect("non zero")), + guild_id: Some(Id::new(300)), + id: Some(Id::new(200)), kind: CommandType::ChatInput, name: "test command".into(), options: Vec::from([CommandOption::SubCommandGroup(OptionsCommandOptionData { @@ -756,7 +756,7 @@ mod tests { ]), })]), })]), - version: Id::new_checked(1).expect("non zero"), + version: Id::new(1), }; serde_test::assert_tokens( diff --git a/model/src/application/command/permissions.rs b/model/src/application/command/permissions.rs index c10e2c5fb7f..f0fe1708702 100644 --- a/model/src/application/command/permissions.rs +++ b/model/src/application/command/permissions.rs @@ -102,7 +102,7 @@ mod tests { #[test] fn test_command_permissions() { let value = CommandPermissions { - id: CommandPermissionsType::Role(Id::new_checked(100).expect("non zero")), + id: CommandPermissionsType::Role(Id::new(100)), permission: true, }; diff --git a/model/src/application/interaction/application_command/data/mod.rs b/model/src/application/interaction/application_command/data/mod.rs index 3d918b80a4a..4aaf10b5604 100644 --- a/model/src/application/interaction/application_command/data/mod.rs +++ b/model/src/application/interaction/application_command/data/mod.rs @@ -370,7 +370,7 @@ mod tests { #[test] fn no_options() { let value = CommandData { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "permissions".to_owned(), options: Vec::new(), resolved: None, @@ -395,7 +395,7 @@ mod tests { #[test] fn subcommand_without_option() { let value = CommandData { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "photo".to_owned(), options: Vec::from([CommandDataOption { focused: false, diff --git a/model/src/application/interaction/application_command/data/resolved.rs b/model/src/application/interaction/application_command/data/resolved.rs index c02497e1feb..e439ed26df6 100644 --- a/model/src/application/interaction/application_command/data/resolved.rs +++ b/model/src/application/interaction/application_command/data/resolved.rs @@ -84,9 +84,9 @@ mod tests { let value = CommandInteractionDataResolved { channels: IntoIterator::into_iter([( - Id::new_checked(100).expect("non zero"), + Id::new(100), InteractionChannel { - id: Id::new_checked(100).expect("non zero"), + id: Id::new(100), kind: ChannelType::GuildText, name: "channel name".into(), parent_id: None, @@ -96,7 +96,7 @@ mod tests { )]) .collect(), members: IntoIterator::into_iter([( - Id::new_checked(300).expect("non zero"), + Id::new(300), InteractionMember { avatar: None, communication_disabled_until: None, @@ -110,7 +110,7 @@ mod tests { )]) .collect(), messages: IntoIterator::into_iter([( - Id::new_checked(4).expect("non zero"), + Id::new(4), Message { activity: None, application: None, @@ -124,7 +124,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -133,14 +133,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -164,7 +164,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "sticker name".to_owned(), }], referenced_message: None, @@ -176,12 +176,12 @@ mod tests { )]) .collect(), roles: IntoIterator::into_iter([( - Id::new_checked(400).expect("non zero"), + Id::new(400), Role { color: 0, hoist: true, icon: None, - id: Id::new_checked(400).expect("non zero"), + id: Id::new(400), managed: false, mentionable: true, name: "test".to_owned(), @@ -193,7 +193,7 @@ mod tests { )]) .collect(), users: IntoIterator::into_iter([( - Id::new_checked(300).expect("non zero"), + Id::new(300), User { accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), @@ -202,7 +202,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(300).expect("non zero"), + id: Id::new(300), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/application/interaction/message_component/mod.rs b/model/src/application/interaction/message_component/mod.rs index f911f15dba5..2417656b241 100644 --- a/model/src/application/interaction/message_component/mod.rs +++ b/model/src/application/interaction/message_component/mod.rs @@ -137,21 +137,21 @@ mod tests { #[test] fn test_author_id() -> Result<(), TimestampParseError> { fn user_id() -> Id { - Id::new_checked(7).expect("non zero") + Id::new(7) } let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?; let in_guild = MessageComponentInteraction { - application_id: Id::new_checked(1).expect("non zero"), - channel_id: Id::new_checked(2).expect("non zero"), + application_id: Id::new(1), + channel_id: Id::new(2), data: MessageComponentInteractionData { custom_id: "foo".to_owned(), component_type: ComponentType::Button, values: Vec::from(["bar".to_owned()]), }, - guild_id: Some(Id::new_checked(3).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(3)), + id: Id::new(4), kind: InteractionType::MessageComponent, member: Some(PartialMember { avatar: None, @@ -171,14 +171,14 @@ mod tests { application_id: None, attachments: Vec::new(), author: user(user_id()), - channel_id: Id::new_checked(5).expect("non zero"), + channel_id: Id::new(5), components: Vec::new(), content: String::new(), edited_timestamp: None, embeds: Vec::new(), flags: None, - guild_id: Some(Id::new_checked(3).expect("non zero")), - id: Id::new_checked(6).expect("non zero"), + guild_id: Some(Id::new(3)), + id: Id::new(6), interaction: None, kind: MessageType::Regular, member: None, diff --git a/model/src/application/interaction/mod.rs b/model/src/application/interaction/mod.rs index eafcd92faf4..bdfe41565c7 100644 --- a/model/src/application/interaction/mod.rs +++ b/model/src/application/interaction/mod.rs @@ -344,20 +344,20 @@ mod test { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = Interaction::ApplicationCommand(Box::new(ApplicationCommand { - application_id: Id::new_checked(100).expect("non zero"), - channel_id: Id::new_checked(200).expect("non zero"), + application_id: Id::new(100), + channel_id: Id::new(200), data: CommandData { - id: Id::new_checked(300).expect("non zero"), + id: Id::new(300), name: "command name".into(), options: Vec::from([CommandDataOption { focused: false, name: "member".into(), - value: CommandOptionValue::User(Id::new_checked(600).expect("non zero")), + value: CommandOptionValue::User(Id::new(600)), }]), resolved: Some(CommandInteractionDataResolved { channels: HashMap::new(), members: IntoIterator::into_iter([( - Id::new_checked(600).expect("non zero"), + Id::new(600), InteractionMember { avatar: None, communication_disabled_until: None, @@ -373,7 +373,7 @@ mod test { messages: HashMap::new(), roles: HashMap::new(), users: IntoIterator::into_iter([( - Id::new_checked(600).expect("non zero"), + Id::new(600), User { accent_color: None, avatar: Some("avatar string".into()), @@ -382,7 +382,7 @@ mod test { discriminator: 1111, email: None, flags: None, - id: Id::new_checked(600).expect("non zero"), + id: Id::new(600), locale: None, mfa_enabled: None, name: "username".into(), @@ -395,8 +395,8 @@ mod test { .collect(), }), }, - guild_id: Some(Id::new_checked(400).expect("non zero")), - id: Id::new_checked(500).expect("non zero"), + guild_id: Some(Id::new(400)), + id: Id::new(500), kind: InteractionType::ApplicationCommand, member: Some(PartialMember { avatar: None, @@ -416,7 +416,7 @@ mod test { discriminator: 1111, email: None, flags: None, - id: Id::new_checked(600).expect("non zero"), + id: Id::new(600), locale: None, mfa_enabled: None, name: "username".into(), diff --git a/model/src/channel/attachment.rs b/model/src/channel/attachment.rs index 7add75687da..7e352afb940 100644 --- a/model/src/channel/attachment.rs +++ b/model/src/channel/attachment.rs @@ -69,7 +69,7 @@ mod tests { filename: "a.png".to_owned(), description: Some("a image".to_owned()), height: Some(184), - id: Id::new_checked(700_000_000_000_000_000).expect("non zero"), + id: Id::new(700_000_000_000_000_000), proxy_url: "https://cdn.example.com/1.png".to_owned(), size: 13_593, url: "https://example.com/1.png".to_owned(), diff --git a/model/src/channel/category_channel.rs b/model/src/channel/category_channel.rs index 2b4b0feb475..8bbf877d6f9 100644 --- a/model/src/channel/category_channel.rs +++ b/model/src/channel/category_channel.rs @@ -28,8 +28,8 @@ mod tests { #[test] fn test_category_channel() { let value = CategoryChannel { - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(2), kind: ChannelType::GuildCategory, name: "category".to_owned(), permission_overwrites: Vec::new(), diff --git a/model/src/channel/channel_mention.rs b/model/src/channel/channel_mention.rs index 63112754f8f..6b5dde664a6 100644 --- a/model/src/channel/channel_mention.rs +++ b/model/src/channel/channel_mention.rs @@ -25,8 +25,8 @@ mod tests { #[test] fn test_channel_mention() { let value = ChannelMention { - guild_id: Id::new_checked(1).expect("non zero"), - id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + id: Id::new(2), kind: ChannelType::GuildText, name: "channel".to_owned(), }; diff --git a/model/src/channel/followed_channel.rs b/model/src/channel/followed_channel.rs index ccfdefb8a75..0100c027a8b 100644 --- a/model/src/channel/followed_channel.rs +++ b/model/src/channel/followed_channel.rs @@ -25,8 +25,8 @@ mod tests { #[test] fn test_followed_channel() { let value = FollowedChannel { - channel_id: Id::new_checked(1).expect("non zero"), - webhook_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(1), + webhook_id: Id::new(2), }; serde_test::assert_tokens( diff --git a/model/src/channel/group.rs b/model/src/channel/group.rs index 81b94e0ec79..573dbc16dca 100644 --- a/model/src/channel/group.rs +++ b/model/src/channel/group.rs @@ -40,14 +40,14 @@ mod tests { #[test] fn test_group() { let value = Group { - application_id: Some(Id::new_checked(1).expect("non zero")), + application_id: Some(Id::new(1)), icon: Some("icon hash".to_owned()), - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::Group, - last_message_id: Some(Id::new_checked(3).expect("non zero")), + last_message_id: Some(Id::new(3)), last_pin_timestamp: None, name: Some("a group".to_owned()), - owner_id: Id::new_checked(4).expect("non zero"), + owner_id: Id::new(4), recipients: Vec::new(), }; @@ -93,14 +93,14 @@ mod tests { let timestamp = Timestamp::from_str("2021-08-10T12:21:10+00:00")?; let value = Group { - application_id: Some(Id::new_checked(1).expect("non zero")), + application_id: Some(Id::new(1)), icon: Some("icon hash".to_owned()), - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::Group, - last_message_id: Some(Id::new_checked(3).expect("non zero")), + last_message_id: Some(Id::new(3)), last_pin_timestamp: Some(timestamp), name: Some("a group".to_owned()), - owner_id: Id::new_checked(4).expect("non zero"), + owner_id: Id::new(4), recipients: Vec::new(), }; diff --git a/model/src/channel/message/allowed_mentions/builder.rs b/model/src/channel/message/allowed_mentions/builder.rs index 8cfb97aca6f..f1e4babfbb8 100644 --- a/model/src/channel/message/allowed_mentions/builder.rs +++ b/model/src/channel/message/allowed_mentions/builder.rs @@ -146,11 +146,11 @@ mod tests { let value = AllowedMentionsBuilder::new() .users() .user_ids(vec![ - Id::new_checked(100).expect("non zero"), - Id::new_checked(200).expect("non zero"), + Id::new(100), + Id::new(200), ]) .roles() - .role_ids(vec![Id::new_checked(300).expect("non zero")]) + .role_ids(vec![Id::new(300)]) .build(); assert_eq!( @@ -158,10 +158,10 @@ mod tests { AllowedMentions { parse: vec![], users: vec![ - Id::new_checked(100).expect("non zero"), - Id::new_checked(200).expect("non zero") + Id::new(100), + Id::new(200) ], - roles: vec![Id::new_checked(300).expect("non zero")], + roles: vec![Id::new(300)], replied_user: false, }, ); diff --git a/model/src/channel/message/allowed_mentions/mod.rs b/model/src/channel/message/allowed_mentions/mod.rs index f878f4f04c9..7234338dfed 100644 --- a/model/src/channel/message/allowed_mentions/mod.rs +++ b/model/src/channel/message/allowed_mentions/mod.rs @@ -74,8 +74,8 @@ mod tests { fn test_full() { let value = AllowedMentions { parse: vec![ParseTypes::Everyone], - users: vec![Id::new_checked(100).expect("non zero")], - roles: vec![Id::new_checked(200).expect("non zero")], + users: vec![Id::new(100)], + roles: vec![Id::new(200)], replied_user: true, }; diff --git a/model/src/channel/message/application.rs b/model/src/channel/message/application.rs index 066dc42f549..517267269a6 100644 --- a/model/src/channel/message/application.rs +++ b/model/src/channel/message/application.rs @@ -23,7 +23,7 @@ mod tests { cover_image: Some("cover".to_owned()), description: "a description".to_owned(), icon: Some("an icon".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "application".to_owned(), }; diff --git a/model/src/channel/message/mention.rs b/model/src/channel/message/mention.rs index c6c91c2d3de..53d78d826e2 100644 --- a/model/src/channel/message/mention.rs +++ b/model/src/channel/message/mention.rs @@ -58,7 +58,7 @@ mod tests { avatar: None, bot: false, discriminator: 1, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), member: None, name: "foo".to_owned(), public_flags: UserFlags::empty(), @@ -99,7 +99,7 @@ mod tests { avatar: None, bot: false, discriminator: 1, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), member: Some(PartialMember { avatar: None, communication_disabled_until: None, diff --git a/model/src/channel/message/mod.rs b/model/src/channel/message/mod.rs index 8f015c4d9aa..fad13997625 100644 --- a/model/src/channel/message/mod.rs +++ b/model/src/channel/message/mod.rs @@ -129,7 +129,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -138,14 +138,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -169,7 +169,7 @@ mod tests { reference: None, sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "sticker name".to_owned(), }], referenced_message: None, @@ -310,10 +310,10 @@ mod tests { cover_image: Some("cover".to_owned()), description: "a description".to_owned(), icon: Some("an icon".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "application".to_owned(), }), - application_id: Some(Id::new_checked(1).expect("non zero")), + application_id: Some(Id::new(1)), attachments: Vec::new(), author: User { accent_color: None, @@ -323,7 +323,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -332,14 +332,14 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), components: Vec::new(), content: "ping".to_owned(), edited_timestamp: Some(edited_timestamp), embeds: Vec::new(), flags: Some(MessageFlags::empty()), - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(4), interaction: None, kind: MessageType::Regular, member: Some(PartialMember { @@ -355,8 +355,8 @@ mod tests { user: None, }), mention_channels: vec![ChannelMention { - guild_id: Id::new_checked(1).expect("non zero"), - id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + id: Id::new(2), kind: ChannelType::GuildText, name: "channel".to_owned(), }], @@ -372,21 +372,21 @@ mod tests { me: true, }], reference: Some(MessageReference { - channel_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Some(Id::new(1)), guild_id: None, message_id: None, fail_if_not_exists: None, }), sticker_items: vec![MessageSticker { format_type: StickerFormatType::Png, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "sticker name".to_owned(), }], referenced_message: None, timestamp, thread: None, tts: false, - webhook_id: Some(Id::new_checked(1).expect("non zero")), + webhook_id: Some(Id::new(1)), }; serde_test::assert_tokens( diff --git a/model/src/channel/message/reference.rs b/model/src/channel/message/reference.rs index b44434fb667..ab81d45ad60 100644 --- a/model/src/channel/message/reference.rs +++ b/model/src/channel/message/reference.rs @@ -25,7 +25,7 @@ mod tests { #[test] fn test_minimal() { let value = MessageReference { - channel_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Some(Id::new(1)), guild_id: None, message_id: None, fail_if_not_exists: None, @@ -50,9 +50,9 @@ mod tests { #[test] fn test_complete() { let value = MessageReference { - channel_id: Some(Id::new_checked(1).expect("non zero")), - guild_id: Some(Id::new_checked(2).expect("non zero")), - message_id: Some(Id::new_checked(3).expect("non zero")), + channel_id: Some(Id::new(1)), + guild_id: Some(Id::new(2)), + message_id: Some(Id::new(3)), fail_if_not_exists: Some(false), }; diff --git a/model/src/channel/message/sticker/message.rs b/model/src/channel/message/sticker/message.rs index ff0434ee7b4..7c4bad3a885 100644 --- a/model/src/channel/message/sticker/message.rs +++ b/model/src/channel/message/sticker/message.rs @@ -37,7 +37,7 @@ mod tests { fn test_full() { let value = MessageSticker { format_type: StickerFormatType::Lottie, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "sticker".into(), }; diff --git a/model/src/channel/message/sticker/mod.rs b/model/src/channel/message/sticker/mod.rs index 539e0b854db..7ebd4723b2a 100644 --- a/model/src/channel/message/sticker/mod.rs +++ b/model/src/channel/message/sticker/mod.rs @@ -104,7 +104,7 @@ mod tests { description: Some("foo2".to_owned()), format_type: StickerFormatType::Png, guild_id: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: StickerType::Standard, name: "sticker name".to_owned(), pack_id: None, @@ -146,11 +146,11 @@ mod tests { available: true, description: Some("sticker".into()), format_type: StickerFormatType::Png, - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(2), kind: StickerType::Guild, name: "stick".into(), - pack_id: Some(Id::new_checked(3).expect("non zero")), + pack_id: Some(Id::new(3)), sort_value: Some(1), tags: "foo,bar,baz".into(), user: Some(User { @@ -161,7 +161,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/channel/message/sticker/pack.rs b/model/src/channel/message/sticker/pack.rs index d5e40228808..c2c6fee9059 100644 --- a/model/src/channel/message/sticker/pack.rs +++ b/model/src/channel/message/sticker/pack.rs @@ -63,21 +63,21 @@ mod tests { #[test] fn test_full() { let value = StickerPack { - banner_asset_id: Some(Id::new_checked(761_773_777_976_819_732).expect("non zero")), - cover_sticker_id: Some(Id::new_checked(749_053_689_419_006_003).expect("non zero")), + banner_asset_id: Some(Id::new(761_773_777_976_819_732)), + cover_sticker_id: Some(Id::new(749_053_689_419_006_003)), description: "Say hello to Wumpus!".into(), - id: Id::new_checked(847_199_849_233_514_549).expect("non zero"), + id: Id::new(847_199_849_233_514_549), name: "Wumpus Beyond".into(), - sku_id: Id::new_checked(847_199_849_233_514_547).expect("non zero"), + sku_id: Id::new(847_199_849_233_514_547), stickers: Vec::from([Sticker { available: true, description: Some("Wumpus waves hello".into()), format_type: StickerFormatType::Lottie, guild_id: None, - id: Id::new_checked(749_054_660_769_218_631).expect("non zero"), + id: Id::new(749_054_660_769_218_631), kind: StickerType::Standard, name: "Wave".into(), - pack_id: Some(Id::new_checked(847_199_849_233_514_549).expect("non zero")), + pack_id: Some(Id::new(847_199_849_233_514_549)), sort_value: Some(12), tags: "wumpus, hello, sup, hi, oi, heyo, heya, yo, wave".into(), user: None, diff --git a/model/src/channel/mod.rs b/model/src/channel/mod.rs index 236a0e176ee..b2f3a949577 100644 --- a/model/src/channel/mod.rs +++ b/model/src/channel/mod.rs @@ -700,20 +700,20 @@ mod tests { Group { application_id: None, icon: None, - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), kind: ChannelType::Group, last_message_id: None, last_pin_timestamp: None, name: Some("a group".to_owned()), - owner_id: Id::new_checked(456).expect("non zero"), + owner_id: Id::new(456), recipients: Vec::new(), } } fn guild_category() -> CategoryChannel { CategoryChannel { - guild_id: Some(Id::new_checked(321).expect("non zero")), - id: Id::new_checked(123).expect("non zero"), + guild_id: Some(Id::new(321)), + id: Id::new(123), kind: ChannelType::GuildCategory, name: "category".to_owned(), permission_overwrites: Vec::new(), @@ -723,8 +723,8 @@ mod tests { fn guild_text() -> TextChannel { TextChannel { - guild_id: Some(Id::new_checked(321).expect("non zero")), - id: Id::new_checked(456).expect("non zero"), + guild_id: Some(Id::new(321)), + id: Id::new(456), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, @@ -741,8 +741,8 @@ mod tests { fn guild_voice() -> VoiceChannel { VoiceChannel { bitrate: 1000, - guild_id: Some(Id::new_checked(321).expect("non zero")), - id: Id::new_checked(789).expect("non zero"), + guild_id: Some(Id::new(321)), + id: Id::new(789), kind: ChannelType::GuildVoice, name: "voice".to_owned(), permission_overwrites: Vec::new(), @@ -757,8 +757,8 @@ mod tests { fn guild_stage() -> VoiceChannel { VoiceChannel { bitrate: 1000, - guild_id: Some(Id::new_checked(321).expect("non zero")), - id: Id::new_checked(789).expect("non zero"), + guild_id: Some(Id::new(321)), + id: Id::new(789), kind: ChannelType::GuildStageVoice, name: "stage".to_owned(), permission_overwrites: Vec::new(), @@ -772,7 +772,7 @@ mod tests { fn private() -> PrivateChannel { PrivateChannel { - id: Id::new_checked(234).expect("non zero"), + id: Id::new(234), last_message_id: None, last_pin_timestamp: None, kind: ChannelType::Private, @@ -782,30 +782,24 @@ mod tests { #[test] fn test_channel_helpers() { - assert_eq!( - Channel::Group(group()).id(), - Id::new_checked(123).expect("non zero") - ); + assert_eq!(Channel::Group(group()).id(), Id::new(123)); assert_eq!( Channel::Guild(GuildChannel::Category(guild_category())).id(), - Id::new_checked(123).expect("non zero") + Id::new(123) ); assert_eq!( Channel::Guild(GuildChannel::Text(guild_text())).id(), - Id::new_checked(456).expect("non zero") + Id::new(456) ); assert_eq!( Channel::Guild(GuildChannel::Voice(guild_voice())).id(), - Id::new_checked(789).expect("non zero") + Id::new(789) ); assert_eq!( Channel::Guild(GuildChannel::Stage(guild_stage())).id(), - Id::new_checked(789).expect("non zero") - ); - assert_eq!( - Channel::Private(private()).id(), - Id::new_checked(234).expect("non zero") + Id::new(789) ); + assert_eq!(Channel::Private(private()).id(), Id::new(234)); } #[test] @@ -879,40 +873,28 @@ mod tests { fn test_guild_channel_guild_id() { assert_eq!( GuildChannel::Category(guild_category()).guild_id(), - Some(Id::new_checked(321).expect("non zero")) + Some(Id::new(321)) ); assert_eq!( GuildChannel::Text(guild_text()).guild_id(), - Some(Id::new_checked(321).expect("non zero")) + Some(Id::new(321)) ); assert_eq!( GuildChannel::Voice(guild_voice()).guild_id(), - Some(Id::new_checked(321).expect("non zero")) + Some(Id::new(321)) ); assert_eq!( GuildChannel::Stage(guild_stage()).guild_id(), - Some(Id::new_checked(321).expect("non zero")) + Some(Id::new(321)) ); } #[test] fn test_guild_channel_id() { - assert_eq!( - GuildChannel::Category(guild_category()).id(), - Id::new_checked(123).expect("non zero") - ); - assert_eq!( - GuildChannel::Text(guild_text()).id(), - Id::new_checked(456).expect("non zero") - ); - assert_eq!( - GuildChannel::Voice(guild_voice()).id(), - Id::new_checked(789).expect("non zero") - ); - assert_eq!( - GuildChannel::Stage(guild_stage()).id(), - Id::new_checked(789).expect("non zero") - ); + assert_eq!(GuildChannel::Category(guild_category()).id(), Id::new(123)); + assert_eq!(GuildChannel::Text(guild_text()).id(), Id::new(456)); + assert_eq!(GuildChannel::Voice(guild_voice()).id(), Id::new(789)); + assert_eq!(GuildChannel::Stage(guild_stage()).id(), Id::new(789)); } #[test] @@ -955,10 +937,10 @@ mod tests { }); let value = GuildChannel::Text(TextChannel { - guild_id: Some(Id::new_checked(1).expect("non zero")), - id: Id::new_checked(2).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(2), kind: ChannelType::GuildText, - last_message_id: Some(Id::new_checked(3).expect("non zero")), + last_message_id: Some(Id::new(3)), last_pin_timestamp: None, name: "hey".to_owned(), nsfw: false, @@ -975,8 +957,8 @@ mod tests { #[test] fn test_guild_category_channel_deserialization() { let value = GuildChannel::Category(CategoryChannel { - id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildCategory, name: "foo".to_owned(), permission_overwrites: Vec::new(), @@ -1003,15 +985,15 @@ mod tests { #[test] fn test_guild_news_channel_deserialization() { let value = GuildChannel::Text(TextChannel { - id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildNews, - last_message_id: Some(Id::new_checked(4).expect("non zero")), + last_message_id: Some(Id::new(4)), last_pin_timestamp: None, name: "news".to_owned(), nsfw: true, permission_overwrites: Vec::new(), - parent_id: Some(Id::new_checked(5).expect("non zero")), + parent_id: Some(Id::new(5)), position: 3, rate_limit_per_user: None, topic: Some("a news channel".to_owned()), @@ -1039,8 +1021,8 @@ mod tests { #[test] fn test_guild_store_channel_deserialization() { let value = GuildChannel::Text(TextChannel { - id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildStore, last_message_id: None, last_pin_timestamp: None, @@ -1077,23 +1059,23 @@ mod tests { let value = GuildChannel::NewsThread(NewsThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(1)).expect("non zero"), - id: Id::new_checked(6).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(6), kind: ChannelType::GuildNewsThread, - last_message_id: Some(Id::new_checked(3)).expect("non zero"), + last_message_id: Some(Id::new(3)), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new_checked(4)).expect("non zero"), + id: Some(Id::new(4)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(5)).expect("non zero"), + user_id: Some(Id::new(5)), }), member_count: 50_u8, message_count: 50_u8, name: "newsthread".into(), - owner_id: Some(Id::new_checked(5)).expect("non zero"), - parent_id: Some(Id::new_checked(2)).expect("non zero"), + owner_id: Some(Id::new(5)), + parent_id: Some(Id::new(2)), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { archived: false, @@ -1141,23 +1123,23 @@ mod tests { let value = GuildChannel::PublicThread(PublicThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(1)).expect("non zero"), - id: Id::new_checked(6).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(6), kind: ChannelType::GuildPublicThread, - last_message_id: Some(Id::new_checked(3)).expect("non zero"), + last_message_id: Some(Id::new(3)), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new_checked(4)).expect("non zero"), + id: Some(Id::new(4)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(5)).expect("non zero"), + user_id: Some(Id::new(5)), }), member_count: 50_u8, message_count: 50_u8, name: "publicthread".into(), - owner_id: Some(Id::new_checked(5)).expect("non zero"), - parent_id: Some(Id::new_checked(2)).expect("non zero"), + owner_id: Some(Id::new(5)), + parent_id: Some(Id::new(2)), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { archived: false, @@ -1206,28 +1188,28 @@ mod tests { let value = GuildChannel::PrivateThread(PrivateThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(1)).expect("non zero"), - id: Id::new_checked(6).expect("non zero"), + guild_id: Some(Id::new(1)), + id: Id::new(6), invitable: Some(true), kind: ChannelType::GuildPrivateThread, - last_message_id: Some(Id::new_checked(3)).expect("non zero"), + last_message_id: Some(Id::new(3)), member: Some(ThreadMember { flags: 0_u64, - id: Some(Id::new_checked(4)).expect("non zero"), + id: Some(Id::new(4)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(5)).expect("non zero"), + user_id: Some(Id::new(5)), }), member_count: 50_u8, message_count: 50_u8, name: "privatethread".into(), - owner_id: Some(Id::new_checked(5)).expect("non zero"), - parent_id: Some(Id::new_checked(2)).expect("non zero"), + owner_id: Some(Id::new(5)), + parent_id: Some(Id::new(2)), permission_overwrites: Vec::from([PermissionOverwrite { allow: Permissions::empty(), deny: Permissions::empty(), - kind: PermissionOverwriteType::Member(Id::new_checked(5).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new(5)), }]), rate_limit_per_user: Some(1000_u64), thread_metadata: ThreadMetadata { diff --git a/model/src/channel/permission_overwrite.rs b/model/src/channel/permission_overwrite.rs index 3f3abdd2da3..694cec7b15a 100644 --- a/model/src/channel/permission_overwrite.rs +++ b/model/src/channel/permission_overwrite.rs @@ -83,14 +83,14 @@ impl<'de> Deserialize<'de> for PermissionOverwrite { let kind = match data.kind { PermissionOverwriteTargetType::Member => { - let id = Id::new_checked(data.id).expect("non zero"); + let id = Id::new(data.id); #[cfg(feature = "tracing")] tracing::trace!(id = %id.get(), kind = ?data.kind); PermissionOverwriteType::Member(id) } PermissionOverwriteTargetType::Role => { - let id = Id::new_checked(data.id).expect("non zero"); + let id = Id::new(data.id); #[cfg(feature = "tracing")] tracing::trace!(id = %id.get(), kind = ?data.kind); @@ -180,7 +180,7 @@ mod tests { let overwrite = PermissionOverwrite { allow: Permissions::CREATE_INVITE, deny: Permissions::KICK_MEMBERS, - kind: PermissionOverwriteType::Member(Id::new_checked(12_345_678).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new(12_345_678)), }; // We can't use serde_test because it doesn't support 128 bit integers. @@ -213,7 +213,7 @@ mod tests { let value = PermissionOverwrite { allow: Permissions::CREATE_INVITE, deny: Permissions::KICK_MEMBERS, - kind: PermissionOverwriteType::Member(Id::new_checked(1).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new(1)), }; let deserialized = serde_json::from_str::(raw).unwrap(); diff --git a/model/src/channel/private_channel.rs b/model/src/channel/private_channel.rs index 220234ecbd3..ceb21d66bf8 100644 --- a/model/src/channel/private_channel.rs +++ b/model/src/channel/private_channel.rs @@ -36,8 +36,8 @@ mod tests { let last_pin_timestamp = Timestamp::from_str("2021-08-10T12:34:00+00:00")?; let value = PrivateChannel { - id: Id::new_checked(1).expect("non zero"), - last_message_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + last_message_id: Some(Id::new(2)), last_pin_timestamp: Some(last_pin_timestamp), kind: ChannelType::Private, recipients: Vec::new(), diff --git a/model/src/channel/reaction.rs b/model/src/channel/reaction.rs index c0d7b542bdd..e5965d0961c 100644 --- a/model/src/channel/reaction.rs +++ b/model/src/channel/reaction.rs @@ -115,7 +115,7 @@ impl<'de> Visitor<'de> for ReactionVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } @@ -195,22 +195,22 @@ mod tests { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = Reaction { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "a".to_owned(), }, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new_checked(5).expect("non zero")], + roles: vec![Id::new(5)], user: User { accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), @@ -219,7 +219,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(4).expect("non zero"), + id: Id::new(4), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -229,8 +229,8 @@ mod tests { verified: None, }, }), - message_id: Id::new_checked(3).expect("non zero"), - user_id: Id::new_checked(4).expect("non zero"), + message_id: Id::new(3), + user_id: Id::new(4), }; serde_test::assert_tokens( @@ -321,14 +321,14 @@ mod tests { #[test] fn test_reaction_without_member() { let value = Reaction { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "a".to_owned(), }, guild_id: None, member: None, - message_id: Id::new_checked(3).expect("non zero"), - user_id: Id::new_checked(4).expect("non zero"), + message_id: Id::new(3), + user_id: Id::new(4), }; serde_test::assert_tokens( diff --git a/model/src/channel/reaction_type.rs b/model/src/channel/reaction_type.rs index cc056c79b12..286e5789a0c 100644 --- a/model/src/channel/reaction_type.rs +++ b/model/src/channel/reaction_type.rs @@ -31,7 +31,7 @@ mod tests { fn test_custom() { let value = ReactionType::Custom { animated: false, - id: Id::new_checked(1337).expect("non zero"), + id: Id::new(1337), name: Some("foo".to_owned()), }; diff --git a/model/src/channel/stage_instance/mod.rs b/model/src/channel/stage_instance/mod.rs index cf6b0a85547..8216a371f46 100644 --- a/model/src/channel/stage_instance/mod.rs +++ b/model/src/channel/stage_instance/mod.rs @@ -27,10 +27,10 @@ mod test { #[test] fn test_stage_instance() { let value = StageInstance { - channel_id: Id::new_checked(100).expect("non zero"), + channel_id: Id::new(100), discoverable_disabled: false, - guild_id: Id::new_checked(200).expect("non zero"), - id: Id::new_checked(300).expect("non zero"), + guild_id: Id::new(200), + id: Id::new(300), privacy_level: PrivacyLevel::Public, topic: "a topic".into(), }; diff --git a/model/src/channel/text_channel.rs b/model/src/channel/text_channel.rs index 5964f12d060..f6c57a451b2 100644 --- a/model/src/channel/text_channel.rs +++ b/model/src/channel/text_channel.rs @@ -45,8 +45,8 @@ mod tests { #[test] fn test_text_channel() { let value = TextChannel { - id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, @@ -100,15 +100,15 @@ mod tests { let last_pin_timestamp = Timestamp::from_str("2021-08-10T12:34:00+00:00")?; let value = TextChannel { - id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildText, - last_message_id: Some(Id::new_checked(3).expect("non zero")), + last_message_id: Some(Id::new(3)), last_pin_timestamp: Some(last_pin_timestamp), name: "foo".to_owned(), nsfw: true, permission_overwrites: Vec::new(), - parent_id: Some(Id::new_checked(4).expect("non zero")), + parent_id: Some(Id::new(4)), position: 3, rate_limit_per_user: Some(10), topic: Some("a topic".to_owned()), diff --git a/model/src/channel/thread/member.rs b/model/src/channel/thread/member.rs index d26d441b3d1..4a2a372e003 100644 --- a/model/src/channel/thread/member.rs +++ b/model/src/channel/thread/member.rs @@ -75,11 +75,11 @@ mod tests { let value = ThreadMember { flags: 3, - id: Some(Id::new_checked(1).expect("non zero")), + id: Some(Id::new(1)), member: None, presence: None, join_timestamp, - user_id: Some(Id::new_checked(2).expect("non zero")), + user_id: Some(Id::new(2)), }; serde_test::assert_tokens( diff --git a/model/src/channel/thread/news.rs b/model/src/channel/thread/news.rs index 0383240533d..05dbf64be9a 100644 --- a/model/src/channel/thread/news.rs +++ b/model/src/channel/thread/news.rs @@ -55,23 +55,23 @@ mod tests { let value = NewsThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new(2)), + id: Id::new(1), kind: ChannelType::GuildNewsThread, - last_message_id: Some(Id::new_checked(5).expect("non zero")), + last_message_id: Some(Id::new(5)), member: Some(ThreadMember { flags: 12, - id: Some(Id::new_checked(10).expect("non zero")), + id: Some(Id::new(10)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(11).expect("non zero")), + user_id: Some(Id::new(11)), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new_checked(3).expect("non zero")), - parent_id: Some(Id::new_checked(4).expect("non zero")), + owner_id: Some(Id::new(3)), + parent_id: Some(Id::new(4)), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { archived: true, diff --git a/model/src/channel/thread/private.rs b/model/src/channel/thread/private.rs index 63a08a819b5..27e7e177af5 100644 --- a/model/src/channel/thread/private.rs +++ b/model/src/channel/thread/private.rs @@ -63,24 +63,24 @@ mod tests { let value = PrivateThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new(2)), + id: Id::new(1), invitable: Some(true), kind: ChannelType::GuildPrivateThread, - last_message_id: Some(Id::new_checked(5).expect("non zero")), + last_message_id: Some(Id::new(5)), member: Some(ThreadMember { flags: 12, - id: Some(Id::new_checked(10)).expect("non zero"), + id: Some(Id::new(10)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(11)).expect("non zero"), + user_id: Some(Id::new(11)), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new_checked(3).expect("non zero")), - parent_id: Some(Id::new_checked(4).expect("non zero")), + owner_id: Some(Id::new(3)), + parent_id: Some(Id::new(4)), permission_overwrites: Vec::new(), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { diff --git a/model/src/channel/thread/public.rs b/model/src/channel/thread/public.rs index 9dbdaac7593..aa730c8f912 100644 --- a/model/src/channel/thread/public.rs +++ b/model/src/channel/thread/public.rs @@ -56,23 +56,23 @@ mod tests { let value = PublicThread { default_auto_archive_duration: Some(AutoArchiveDuration::Hour), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Id::new_checked(1).expect("non zero"), + guild_id: Some(Id::new(2)), + id: Id::new(1), kind: ChannelType::GuildPublicThread, - last_message_id: Some(Id::new_checked(5).expect("non zero")), + last_message_id: Some(Id::new(5)), member: Some(ThreadMember { flags: 12, - id: Some(Id::new_checked(10).expect("non zero")), + id: Some(Id::new(10)), join_timestamp: timestamp, member: None, presence: None, - user_id: Some(Id::new_checked(11).expect("non zero")), + user_id: Some(Id::new(11)), }), member_count: 7, message_count: 6, name: "test".to_owned(), - owner_id: Some(Id::new_checked(3).expect("non zero")), - parent_id: Some(Id::new_checked(4).expect("non zero")), + owner_id: Some(Id::new(3)), + parent_id: Some(Id::new(4)), rate_limit_per_user: Some(8), thread_metadata: ThreadMetadata { archived: true, diff --git a/model/src/channel/voice_channel.rs b/model/src/channel/voice_channel.rs index ba8e18d6280..233d7c6dab2 100644 --- a/model/src/channel/voice_channel.rs +++ b/model/src/channel/voice_channel.rs @@ -40,9 +40,9 @@ mod tests { #[test] fn test_voice_channel() { let value = VoiceChannel { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), bitrate: 124_000, - guild_id: Some(Id::new_checked(2).expect("non zero")), + guild_id: Some(Id::new(2)), kind: ChannelType::GuildVoice, name: "foo".to_owned(), permission_overwrites: Vec::new(), @@ -90,13 +90,13 @@ mod tests { fn test_voice_channel_complete() { fn channel(kind: ChannelType) -> VoiceChannel { VoiceChannel { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), bitrate: 124_000, - guild_id: Some(Id::new_checked(2).expect("non zero")), + guild_id: Some(Id::new(2)), kind, name: "foo".to_owned(), permission_overwrites: Vec::new(), - parent_id: Some(Id::new_checked(3).expect("non zero")), + parent_id: Some(Id::new(3)), position: 3, rtc_region: Some("a".to_owned()), user_limit: Some(7), diff --git a/model/src/channel/webhook/mod.rs b/model/src/channel/webhook/mod.rs index e45fe4eab9b..bae846bfa6f 100644 --- a/model/src/channel/webhook/mod.rs +++ b/model/src/channel/webhook/mod.rs @@ -80,11 +80,11 @@ mod tests { #[test] fn test_webhook() { let value = Webhook { - application_id: Some(Id::new_checked(4).expect("non zero")), + application_id: Some(Id::new(4)), avatar: Some("avatar".to_owned()), - channel_id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Id::new_checked(3).expect("non zero"), + channel_id: Id::new(1), + guild_id: Some(Id::new(2)), + id: Id::new(3), kind: WebhookType::Incoming, name: Some("a webhook".to_owned()), source_channel: None, @@ -135,20 +135,20 @@ mod tests { #[test] fn test_webhook_complete() { let value = Webhook { - application_id: Some(Id::new_checked(4).expect("non zero")), + application_id: Some(Id::new(4)), avatar: Some("avatar".to_owned()), - channel_id: Id::new_checked(1).expect("non zero"), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Id::new_checked(3).expect("non zero"), + channel_id: Id::new(1), + guild_id: Some(Id::new(2)), + id: Id::new(3), kind: WebhookType::Incoming, name: Some("a webhook".to_owned()), source_channel: Some(WebhookChannel { - id: Id::new_checked(4).expect("non zero"), + id: Id::new(4), name: "webhook channel".into(), }), source_guild: Some(WebhookGuild { icon: Some("guild icon".into()), - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), name: "webhook guild".into(), }), token: Some("a token".to_owned()), @@ -161,7 +161,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/gateway/event/gateway.rs b/model/src/gateway/event/gateway.rs index 4b9701d82b1..4f648b30f28 100644 --- a/model/src/gateway/event/gateway.rs +++ b/model/src/gateway/event/gateway.rs @@ -852,8 +852,8 @@ mod tests { #[test] fn test_serialize_dispatch() { let role_delete = RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), }; let dispatch = Box::new(DispatchEvent::RoleDelete(role_delete)); let value = GatewayEvent::Dispatch(2_048, dispatch); diff --git a/model/src/gateway/payload/incoming/guild_delete.rs b/model/src/gateway/payload/incoming/guild_delete.rs index 37f9b6ac798..ed338f4c600 100644 --- a/model/src/gateway/payload/incoming/guild_delete.rs +++ b/model/src/gateway/payload/incoming/guild_delete.rs @@ -23,7 +23,7 @@ mod tests { #[test] fn test_guild_delete_available() { let expected = GuildDelete { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), unavailable: true, }; @@ -62,7 +62,7 @@ mod tests { #[test] fn test_guild_delete_unavailable() { let expected = GuildDelete { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), unavailable: false, }; @@ -101,7 +101,7 @@ mod tests { #[test] fn test_guild_delete_unavailable_null_default() { let expected = GuildDelete { - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), unavailable: false, }; diff --git a/model/src/gateway/payload/incoming/invite_create.rs b/model/src/gateway/payload/incoming/invite_create.rs index c1651da540a..47a48b0308c 100644 --- a/model/src/gateway/payload/incoming/invite_create.rs +++ b/model/src/gateway/payload/incoming/invite_create.rs @@ -133,10 +133,10 @@ mod tests { let created_at = Timestamp::from_secs(1_609_459_200).expect("non zero"); let value = InviteCreate { - channel_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new(1), code: "a".repeat(7), created_at, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), inviter: None, max_age: 3600, max_uses: 5, @@ -181,7 +181,7 @@ mod tests { let value = PartialUser { avatar: Some("a".repeat(32)), discriminator: 123, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), username: "twilight".to_owned(), }; diff --git a/model/src/gateway/payload/incoming/member_add.rs b/model/src/gateway/payload/incoming/member_add.rs index f512e58300d..9b10c4da57e 100644 --- a/model/src/gateway/payload/incoming/member_add.rs +++ b/model/src/gateway/payload/incoming/member_add.rs @@ -33,7 +33,7 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: None, @@ -41,7 +41,7 @@ mod tests { premium_since: None, roles: vec![], user: User { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), accent_color: None, avatar: None, banner: None, diff --git a/model/src/gateway/payload/incoming/member_chunk.rs b/model/src/gateway/payload/incoming/member_chunk.rs index 00e363c458e..a7e8520ed72 100644 --- a/model/src/gateway/payload/incoming/member_chunk.rs +++ b/model/src/gateway/payload/incoming/member_chunk.rs @@ -124,7 +124,7 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { // a temporary placeholder value and update it with the real // guild ID after all the fields have been deserialized. let deserializer = - MemberListDeserializer::new(Id::new_checked(1).expect("non zero")); + MemberListDeserializer::new(Id::new(1)); members = Some(map.next_value_seed(deserializer)?); } @@ -148,7 +148,7 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { } let deserializer = - PresenceListDeserializer::new(Id::new_checked(1).expect("non zero")); + PresenceListDeserializer::new(Id::new(1)); presences = Some(map.next_value_seed(deserializer)?); } @@ -329,24 +329,24 @@ mod tests { let expected = MemberChunk { chunk_count: 1, chunk_index: 0, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), members: Vec::from([ Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, roles: vec![ - Id::new_checked(6).expect("non zero"), - Id::new_checked(7).expect("non zero"), + Id::new(6), + Id::new(7), ], user: User { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), accent_color: None, avatar: Some("dddddddddddddddddddddddddddddddd".to_owned()), banner: None, @@ -367,15 +367,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new_checked(6).expect("non zero")], + roles: vec![Id::new(6)], user: User { - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), accent_color: None, avatar: Some("cccccccccccccccccccccccccccccccc".to_owned()), banner: None, @@ -396,15 +396,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: true, premium_since: None, - roles: vec![Id::new_checked(6).expect("non zero")], + roles: vec![Id::new(6)], user: User { - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), banner: None, @@ -425,15 +425,15 @@ mod tests { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new_checked(6).expect("non zero")], + roles: vec![Id::new(6)], user: User { - id: Id::new_checked(6).expect("non zero"), + id: Id::new(6), accent_color: None, avatar: Some("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".to_owned()), banner: None, @@ -461,10 +461,10 @@ mod tests { mobile: None, web: Some(Status::Online), }, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), status: Status::Online, user: UserOrId::UserId { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), }, }, Presence { @@ -474,10 +474,10 @@ mod tests { mobile: None, web: Some(Status::Online), }, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), status: Status::Online, user: UserOrId::UserId { - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), }, }, Presence { @@ -487,10 +487,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), status: Status::DoNotDisturb, user: UserOrId::UserId { - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), }, }, ]), diff --git a/model/src/gateway/payload/incoming/member_update.rs b/model/src/gateway/payload/incoming/member_update.rs index e6653fb5a7e..84bcd35bb07 100644 --- a/model/src/gateway/payload/incoming/member_update.rs +++ b/model/src/gateway/payload/incoming/member_update.rs @@ -45,7 +45,7 @@ mod tests { let value = MemberUpdate { avatar: None, - guild_id: Id::new_checked(1_234).expect("non zero"), + guild_id: Id::new(1_234), deaf: Some(false), joined_at, @@ -59,7 +59,7 @@ mod tests { banner: None, name: "Twilight Sparkle".to_string(), public_flags: None, - id: Id::new_checked(424_242).expect("non zero"), + id: Id::new(424_242), discriminator: 1234, avatar: Some("cool image".to_string()), bot: false, diff --git a/model/src/gateway/payload/incoming/ready.rs b/model/src/gateway/payload/incoming/ready.rs index 031e50c6f78..b0772469f58 100644 --- a/model/src/gateway/payload/incoming/ready.rs +++ b/model/src/gateway/payload/incoming/ready.rs @@ -29,11 +29,11 @@ mod tests { fn test_ready() { let guilds = vec![ UnavailableGuild { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), unavailable: true, }, UnavailableGuild { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), unavailable: true, }, ]; @@ -41,7 +41,7 @@ mod tests { let ready = Ready { application: PartialApplication { flags: ApplicationFlags::empty(), - id: Id::new_checked(100).expect("non zero"), + id: Id::new(100), }, guilds, session_id: "foo".to_owned(), @@ -54,7 +54,7 @@ mod tests { discriminator: 1212, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: false, name: "bar".to_owned(), diff --git a/model/src/gateway/payload/incoming/role_delete.rs b/model/src/gateway/payload/incoming/role_delete.rs index 2a516615171..08d48b9ff47 100644 --- a/model/src/gateway/payload/incoming/role_delete.rs +++ b/model/src/gateway/payload/incoming/role_delete.rs @@ -19,8 +19,8 @@ mod tests { #[test] fn test_webhooks_update() { let value = RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/role_update.rs b/model/src/gateway/payload/incoming/role_update.rs index 384e85ccb76..9e196159e01 100644 --- a/model/src/gateway/payload/incoming/role_update.rs +++ b/model/src/gateway/payload/incoming/role_update.rs @@ -19,12 +19,12 @@ mod tests { #[test] fn test_role_update() { let value = RoleUpdate { - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), role: Role { color: 0, hoist: true, icon: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), managed: false, mentionable: false, name: "a role".to_owned(), diff --git a/model/src/gateway/payload/incoming/thread_members_update.rs b/model/src/gateway/payload/incoming/thread_members_update.rs index 7848e2117b4..9d09e347bd7 100644 --- a/model/src/gateway/payload/incoming/thread_members_update.rs +++ b/model/src/gateway/payload/incoming/thread_members_update.rs @@ -112,7 +112,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -127,7 +127,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -167,10 +167,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), status: Status::Online, user: UserOrId::UserId { - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), }, }; @@ -179,14 +179,14 @@ mod tests { let value = ThreadMembersUpdate { added_members: vec![ThreadMember { flags: 1, - id: Some(Id::new_checked(123).expect("non zero")), + id: Some(Id::new(123)), join_timestamp, member: Some(member), presence: Some(presence), - user_id: Some(Id::new_checked(3).expect("non zero")), + user_id: Some(Id::new(3)), }], - guild_id: Id::new_checked(2).expect("non zero"), - id: Id::new_checked(4).expect("non zero"), + guild_id: Id::new(2), + id: Id::new(4), member_count: 8, removed_member_ids: vec![], }; diff --git a/model/src/gateway/payload/incoming/typing_start.rs b/model/src/gateway/payload/incoming/typing_start.rs index 7d75bf2fd30..1550e4c5d26 100644 --- a/model/src/gateway/payload/incoming/typing_start.rs +++ b/model/src/gateway/payload/incoming/typing_start.rs @@ -106,7 +106,7 @@ impl<'de> Visitor<'de> for TypingStartVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } @@ -183,21 +183,21 @@ mod tests { let joined_at = Timestamp::from_str("2020-01-01T00:00:00.000000+00:00")?; let value = TypingStart { - channel_id: Id::new_checked(2).expect("non zero"), - guild_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Id::new(2), + guild_id: Some(Id::new(1)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new_checked(4).expect("non zero")], + roles: vec![Id::new(4)], user: User { - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), accent_color: None, avatar: Some("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned()), banner: None, @@ -215,7 +215,7 @@ mod tests { }, }), timestamp: 1_500_000_000, - user_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new(3), }; serde_test::assert_tokens( @@ -297,11 +297,11 @@ mod tests { #[test] fn test_typing_start_without_member() { let value = TypingStart { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), guild_id: None, member: None, timestamp: 1_500_000_000, - user_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new(3), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/unavailable_guild.rs b/model/src/gateway/payload/incoming/unavailable_guild.rs index 202a99588a1..80cfa3c8fea 100644 --- a/model/src/gateway/payload/incoming/unavailable_guild.rs +++ b/model/src/gateway/payload/incoming/unavailable_guild.rs @@ -15,7 +15,7 @@ mod tests { #[test] fn test_unavailable_guild() { let value = UnavailableGuild { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/incoming/voice_state_update.rs b/model/src/gateway/payload/incoming/voice_state_update.rs index 398f79faa91..d778db87298 100644 --- a/model/src/gateway/payload/incoming/voice_state_update.rs +++ b/model/src/gateway/payload/incoming/voice_state_update.rs @@ -24,20 +24,20 @@ mod tests { let value = VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: false, nick: None, pending: false, premium_since: None, - roles: vec![Id::new_checked(4).expect("non zero")], + roles: vec![Id::new(4)], user: User { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), accent_color: None, avatar: None, banner: None, @@ -61,7 +61,7 @@ mod tests { session_id: "a".to_owned(), suppress: false, token: None, - user_id: Id::new_checked(1).expect("non zero"), + user_id: Id::new(1), request_to_speak_timestamp: None, }); @@ -162,23 +162,23 @@ mod tests { let value = VoiceStateUpdate(VoiceState { channel_id: None, deaf: false, - guild_id: Some(Id::new_checked(999_999).expect("non zero")), + guild_id: Some(Id::new(999_999)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(999_999).expect("non zero"), + guild_id: Id::new(999_999), joined_at, mute: false, nick: Some("Twilight".to_string()), pending: false, premium_since: None, roles: vec![ - Id::new_checked(123).expect("non zero"), - Id::new_checked(124).expect("non zero"), + Id::new(123), + Id::new(124), ], user: User { - id: Id::new_checked(1_234_123_123_123).expect("non zero"), + id: Id::new(1_234_123_123_123), accent_color: None, avatar: Some("a21312321231236060dfe562c".to_string()), banner: None, @@ -202,7 +202,7 @@ mod tests { session_id: "asdasdas1da98da2b3ab3a".to_owned(), suppress: false, token: None, - user_id: Id::new_checked(123_213).expect("non zero"), + user_id: Id::new(123_213), request_to_speak_timestamp: Some(request_to_speak_timestamp), }); diff --git a/model/src/gateway/payload/incoming/webhooks_update.rs b/model/src/gateway/payload/incoming/webhooks_update.rs index 79e67453a45..7a27bb5037f 100644 --- a/model/src/gateway/payload/incoming/webhooks_update.rs +++ b/model/src/gateway/payload/incoming/webhooks_update.rs @@ -19,8 +19,8 @@ mod tests { #[test] fn test_webhooks_update() { let value = WebhooksUpdate { - channel_id: Id::new_checked(1).expect("non zero"), - guild_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(1), + guild_id: Id::new(2), }; serde_test::assert_tokens( diff --git a/model/src/gateway/payload/outgoing/request_guild_members.rs b/model/src/gateway/payload/outgoing/request_guild_members.rs index 04525330949..15a05927dfd 100644 --- a/model/src/gateway/payload/outgoing/request_guild_members.rs +++ b/model/src/gateway/payload/outgoing/request_guild_members.rs @@ -144,11 +144,11 @@ impl RequestGuildMembersBuilder { /// ``` /// use twilight_model::{gateway::payload::outgoing::RequestGuildMembers, id::Id}; /// - /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new(1)) /// .presences(true) /// .query("a", None); /// - /// assert_eq!(Id::new_checked(1).expect("non zero"), request.d.guild_id); + /// assert_eq!(Id::new(1), request.d.guild_id); /// assert_eq!(Some(0), request.d.limit); /// assert_eq!(Some("a"), request.d.query.as_deref()); /// assert_eq!(Some(true), request.d.presences); @@ -187,11 +187,11 @@ impl RequestGuildMembersBuilder { /// id::Id, /// }; /// - /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new(1)) /// .nonce("test") - /// .user_id(Id::new_checked(2).expect("non zero")); + /// .user_id(Id::new(2)); /// - /// assert_eq!(Some(RequestGuildMemberId::One(Id::new_checked(2).expect("non zero"))), request.d.user_ids); + /// assert_eq!(Some(RequestGuildMemberId::One(Id::new(2))), request.d.user_ids); /// ``` #[allow(clippy::missing_const_for_fn)] pub fn user_id(self, user_id: Id) -> RequestGuildMembers { @@ -227,9 +227,9 @@ impl RequestGuildMembersBuilder { /// }; /// /// # fn main() -> Result<(), Box> { - /// let request = RequestGuildMembers::builder(Id::new_checked(1).expect("non zero")) + /// let request = RequestGuildMembers::builder(Id::new(1)) /// .nonce("test") - /// .user_ids(vec![Id::new_checked(2).expect("non zero"), Id::new_checked(2).expect("non zero")])?; + /// .user_ids(vec![Id::new(2), Id::new(2)])?; /// /// assert!(matches!(request.d.user_ids, Some(RequestGuildMemberId::Multiple(ids)) if ids.len() == 2)); /// # Ok(()) } diff --git a/model/src/gateway/presence/mod.rs b/model/src/gateway/presence/mod.rs index 259fcb33a4b..63ce84c9c63 100644 --- a/model/src/gateway/presence/mod.rs +++ b/model/src/gateway/presence/mod.rs @@ -210,10 +210,10 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), status: Status::Online, user: UserOrId::UserId { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), }, }; @@ -314,15 +314,15 @@ mod tests { mobile: None, web: None, }, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), status: Status::Online, user: UserOrId::UserId { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), }, }]); let mut json_deserializer = Deserializer::from_str(input); - let deserializer = PresenceListDeserializer::new(Id::new_checked(2).expect("non zero")); + let deserializer = PresenceListDeserializer::new(Id::new(2)); let actual = deserializer.deserialize(&mut json_deserializer).unwrap(); assert_eq!(actual, expected); diff --git a/model/src/guild/audit_log/change.rs b/model/src/guild/audit_log/change.rs index d66898f01cd..8f3cbbc71f9 100644 --- a/model/src/guild/audit_log/change.rs +++ b/model/src/guild/audit_log/change.rs @@ -856,7 +856,7 @@ mod tests { #[test] fn test_afk_channel_id() { let value = AuditLogChange::AfkChannelId { - new: Some(Id::new_checked(1).expect("non zero")), + new: Some(Id::new(1)), old: None, }; diff --git a/model/src/guild/audit_log/entry.rs b/model/src/guild/audit_log/entry.rs index 4396219b65c..d1c28c965ad 100644 --- a/model/src/guild/audit_log/entry.rs +++ b/model/src/guild/audit_log/entry.rs @@ -76,11 +76,11 @@ mod tests { new: None, old: Some(OLD.to_owned()), }]), - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), options: None, reason: Some("some reason".to_owned()), - target_id: Some(Id::new_checked(2).expect("non zero")), - user_id: Some(Id::new_checked(1).expect("non zero")), + target_id: Some(Id::new(2)), + user_id: Some(Id::new(1)), }; serde_test::assert_tokens( diff --git a/model/src/guild/ban.rs b/model/src/guild/ban.rs index ff93b358210..989a61698a3 100644 --- a/model/src/guild/ban.rs +++ b/model/src/guild/ban.rs @@ -25,7 +25,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), + id: Id::new(100_000_000_000_000_000), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/guild/emoji.rs b/model/src/guild/emoji.rs index b59624b8b6e..6c573a31c59 100644 --- a/model/src/guild/emoji.rs +++ b/model/src/guild/emoji.rs @@ -40,7 +40,7 @@ mod tests { let emoji = Emoji { animated: false, available: true, - id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), + id: Id::new(100_000_000_000_000_000), managed: false, name: "test".to_owned(), require_colons: true, @@ -53,7 +53,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -116,11 +116,11 @@ mod tests { let emoji = Emoji { animated: false, available: true, - id: Id::new_checked(100_000_000_000_000_000).expect("non zero"), + id: Id::new(100_000_000_000_000_000), managed: false, name: "test".to_owned(), require_colons: true, - roles: vec![Id::new_checked(1).expect("non zero")], + roles: vec![Id::new(1)], user: Some(User { accent_color: None, avatar: None, @@ -129,7 +129,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/guild/info.rs b/model/src/guild/info.rs index 752faa6a904..46f016034af 100644 --- a/model/src/guild/info.rs +++ b/model/src/guild/info.rs @@ -23,7 +23,7 @@ mod tests { fn test_guild_info() { let value = GuildInfo { icon: Some("icon hash".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "guild name".to_owned(), owner: false, permissions: Permissions::MANAGE_CHANNELS, diff --git a/model/src/guild/integration.rs b/model/src/guild/integration.rs index 708ccb78299..72ce57649c1 100644 --- a/model/src/guild/integration.rs +++ b/model/src/guild/integration.rs @@ -70,11 +70,11 @@ mod tests { expire_behavior: Some(IntegrationExpireBehavior::Kick), expire_grace_period: Some(3_600), guild_id: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: "a".to_owned(), name: "integration name".to_owned(), revoked: Some(false), - role_id: Some(Id::new_checked(3).expect("non zero")), + role_id: Some(Id::new(3)), subscriber_count: Some(1337), synced_at: Some(synced_at), syncing: Some(false), @@ -86,7 +86,7 @@ mod tests { discriminator: 1000, email: None, flags: None, - id: Id::new_checked(4).expect("non zero"), + id: Id::new(4), locale: None, mfa_enabled: None, name: "user".to_owned(), @@ -192,7 +192,7 @@ mod tests { bot: None, description: "Friendship is Magic".to_string(), icon: None, - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }), @@ -201,11 +201,11 @@ mod tests { expire_behavior: Some(IntegrationExpireBehavior::Kick), expire_grace_period: Some(3_600), guild_id: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: "a".to_owned(), name: "integration name".to_owned(), revoked: Some(false), - role_id: Some(Id::new_checked(3).expect("non zero")), + role_id: Some(Id::new(3)), subscriber_count: Some(1337), synced_at: Some(synced_at), syncing: Some(false), @@ -217,7 +217,7 @@ mod tests { discriminator: 1000, email: None, flags: None, - id: Id::new_checked(4).expect("non zero"), + id: Id::new(4), locale: None, mfa_enabled: None, name: "user".to_owned(), diff --git a/model/src/guild/integration_application.rs b/model/src/guild/integration_application.rs index 7a5c0dc07a4..8b48aa98a3a 100644 --- a/model/src/guild/integration_application.rs +++ b/model/src/guild/integration_application.rs @@ -28,7 +28,7 @@ mod tests { bot: None, description: "Friendship is Magic".to_string(), icon: None, - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }; @@ -67,7 +67,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -78,7 +78,7 @@ mod tests { }), description: "Friendship is Magic".to_string(), icon: None, - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), name: "Twilight".to_string(), summary: "A cool pony".to_string(), }; diff --git a/model/src/guild/member.rs b/model/src/guild/member.rs index fc0abd5a450..8c7bea14551 100644 --- a/model/src/guild/member.rs +++ b/model/src/guild/member.rs @@ -229,7 +229,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -244,7 +244,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -325,7 +325,7 @@ mod tests { avatar: Some("guild avatar".to_owned()), communication_disabled_until: Some(communication_disabled_until), deaf: false, - guild_id: Id::new_checked(1).expect("non zero"), + guild_id: Id::new(1), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -340,7 +340,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "twilight".to_owned(), diff --git a/model/src/guild/mod.rs b/model/src/guild/mod.rs index 11ec66cba6e..f7b9b53c904 100644 --- a/model/src/guild/mod.rs +++ b/model/src/guild/mod.rs @@ -431,8 +431,7 @@ impl<'de> Deserialize<'de> for Guild { return Err(DeError::duplicate_field("members")); } - let deserializer = - MemberListDeserializer::new(Id::new_checked(1).expect("non zero")); + let deserializer = MemberListDeserializer::new(Id::new(1)); members = Some(map.next_value_seed(deserializer)?); } @@ -504,9 +503,7 @@ impl<'de> Deserialize<'de> for Guild { return Err(DeError::duplicate_field("presences")); } - let deserializer = PresenceListDeserializer::new( - Id::new_checked(1).expect("non zero"), - ); + let deserializer = PresenceListDeserializer::new(Id::new(1)); presences = Some(map.next_value_seed(deserializer)?); } @@ -895,9 +892,9 @@ mod tests { let joined_at = Timestamp::from_str("2015-04-26T06:26:56.936000+00:00")?; let value = Guild { - afk_channel_id: Some(Id::new_checked(2).expect("non zero")), + afk_channel_id: Some(Id::new(2)), afk_timeout: 900, - application_id: Some(Id::new_checked(3).expect("non zero")), + application_id: Some(Id::new(3)), approximate_member_count: Some(1_200), approximate_presence_count: Some(900), banner: Some("banner hash".to_owned()), @@ -909,7 +906,7 @@ mod tests { explicit_content_filter: ExplicitContentFilter::MembersWithoutRole, features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), joined_at: Some(joined_at), large: true, max_members: Some(25_000), @@ -920,7 +917,7 @@ mod tests { mfa_level: MfaLevel::Elevated, name: "the name".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new_checked(5).expect("non zero"), + owner_id: Id::new(5), owner: Some(false), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-us".to_owned(), @@ -928,18 +925,18 @@ mod tests { premium_tier: PremiumTier::Tier1, presences: Vec::new(), roles: Vec::new(), - rules_channel_id: Some(Id::new_checked(6).expect("non zero")), + rules_channel_id: Some(Id::new(6)), splash: Some("splash hash".to_owned()), stage_instances: Vec::new(), stickers: Vec::new(), system_channel_flags: SystemChannelFlags::SUPPRESS_PREMIUM_SUBSCRIPTIONS, - system_channel_id: Some(Id::new_checked(7).expect("non zero")), + system_channel_id: Some(Id::new(7)), threads: Vec::new(), unavailable: false, vanity_url_code: Some("twilight".to_owned()), verification_level: VerificationLevel::Medium, voice_states: Vec::new(), - widget_channel_id: Some(Id::new_checked(8).expect("non zero")), + widget_channel_id: Some(Id::new(8)), widget_enabled: Some(true), }; diff --git a/model/src/guild/partial_guild.rs b/model/src/guild/partial_guild.rs index 564b494fa2f..8b1217a76a5 100644 --- a/model/src/guild/partial_guild.rs +++ b/model/src/guild/partial_guild.rs @@ -68,10 +68,10 @@ mod tests { #[test] fn test_partial_guild() { let value = PartialGuild { - id: Id::new_checked(1).expect("non zero"), - afk_channel_id: Some(Id::new_checked(2).expect("non zero")), + id: Id::new(1), + afk_channel_id: Some(Id::new(2)), afk_timeout: 900, - application_id: Some(Id::new_checked(3).expect("non zero")), + application_id: Some(Id::new(3)), banner: Some("banner hash".to_owned()), default_message_notifications: DefaultMessageNotificationLevel::Mentions, description: Some("a description".to_owned()), @@ -86,20 +86,20 @@ mod tests { mfa_level: MfaLevel::Elevated, name: "the name".to_owned(), nsfw_level: NSFWLevel::Default, - owner_id: Id::new_checked(5).expect("non zero"), + owner_id: Id::new(5), owner: Some(false), permissions: Some(Permissions::SEND_MESSAGES), preferred_locale: "en-us".to_owned(), premium_subscription_count: Some(3), premium_tier: PremiumTier::Tier1, roles: Vec::new(), - rules_channel_id: Some(Id::new_checked(6).expect("non zero")), + rules_channel_id: Some(Id::new(6)), splash: Some("splash hash".to_owned()), system_channel_flags: SystemChannelFlags::SUPPRESS_PREMIUM_SUBSCRIPTIONS, - system_channel_id: Some(Id::new_checked(7).expect("non zero")), + system_channel_id: Some(Id::new(7)), verification_level: VerificationLevel::Medium, vanity_url_code: Some("twilight".to_owned()), - widget_channel_id: Some(Id::new_checked(8).expect("non zero")), + widget_channel_id: Some(Id::new(8)), widget_enabled: Some(true), }; diff --git a/model/src/guild/partial_member.rs b/model/src/guild/partial_member.rs index c67fdcfed1e..3299f59791c 100644 --- a/model/src/guild/partial_member.rs +++ b/model/src/guild/partial_member.rs @@ -51,7 +51,7 @@ mod tests { nick: Some("a nickname".to_owned()), permissions: None, premium_since: None, - roles: vec![Id::new_checked(1).expect("non zero")], + roles: vec![Id::new(1)], user: None, }; diff --git a/model/src/guild/preview.rs b/model/src/guild/preview.rs index 01d428cd5e6..5b6d72c1691 100644 --- a/model/src/guild/preview.rs +++ b/model/src/guild/preview.rs @@ -34,7 +34,7 @@ mod tests { emojis: vec![Emoji { animated: false, available: true, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), managed: false, name: "test".to_owned(), require_colons: true, @@ -42,7 +42,7 @@ mod tests { user: None, }], features: vec!["a feature".to_owned()], - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "guild name".to_owned(), icon: Some("icon hash".to_owned()), splash: Some("splash hash".to_owned()), diff --git a/model/src/guild/role.rs b/model/src/guild/role.rs index 0f272fda90a..c971c029005 100644 --- a/model/src/guild/role.rs +++ b/model/src/guild/role.rs @@ -57,7 +57,7 @@ impl Ord for Role { /// # use twilight_model::{guild::{Permissions, Role}, id::Id}; /// # use std::cmp::Ordering; /// let role_a = Role { - /// id: Id::new_checked(123).expect("non zero"), + /// id: Id::new(123), /// position: 12, ///# color: 0, ///# hoist: true, @@ -71,7 +71,7 @@ impl Ord for Role { /// // ... /// }; /// let role_b = Role { - /// id: Id::new_checked(456).expect("non zero"), + /// id: Id::new(456), /// position: 13, ///# color: 0, ///# hoist: true, @@ -96,7 +96,7 @@ impl Ord for Role { /// # use twilight_model::{guild::{Permissions, Role}, id::Id}; /// # use std::cmp::Ordering; /// let role_a = Role { - /// id: Id::new_checked(123).expect("non zero"), + /// id: Id::new(123), /// position: 12, ///# color: 0, ///# hoist: true, @@ -109,7 +109,7 @@ impl Ord for Role { ///# unicode_emoji: None, /// }; /// let role_b = Role { - /// id: Id::new_checked(456).expect("non zero"), + /// id: Id::new(456), /// position: 12, ///# color: 0, ///# hoist: true, @@ -178,7 +178,7 @@ mod tests { color: 0, hoist: true, icon: None, - id: Id::new_checked(123).expect("non zero"), + id: Id::new(123), managed: false, mentionable: true, name: "test".to_owned(), diff --git a/model/src/guild/role_tags.rs b/model/src/guild/role_tags.rs index 985d1e9a4cc..62870c80540 100644 --- a/model/src/guild/role_tags.rs +++ b/model/src/guild/role_tags.rs @@ -77,8 +77,8 @@ mod tests { #[test] fn test_role_tags_all() { let tags = RoleTags { - bot_id: Some(Id::new_checked(1).expect("non zero")), - integration_id: Some(Id::new_checked(2).expect("non zero")), + bot_id: Some(Id::new(1)), + integration_id: Some(Id::new(2)), premium_subscriber: true, }; diff --git a/model/src/guild/unavailable_guild.rs b/model/src/guild/unavailable_guild.rs index c0f7acc9a37..1b0ce3e46ff 100644 --- a/model/src/guild/unavailable_guild.rs +++ b/model/src/guild/unavailable_guild.rs @@ -16,7 +16,7 @@ mod tests { #[test] fn test_unavailable_guild() { let value = UnavailableGuild { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), unavailable: true, }; diff --git a/model/src/guild/widget.rs b/model/src/guild/widget.rs index 44e4fd49ab0..f80904ffd38 100644 --- a/model/src/guild/widget.rs +++ b/model/src/guild/widget.rs @@ -16,7 +16,7 @@ mod tests { #[test] fn test_guild_widget() { let value = GuildWidget { - channel_id: Id::new_checked(111_111_111_111_111_111).expect("non zero"), + channel_id: Id::new(111_111_111_111_111_111), enabled: true, }; diff --git a/model/src/id/mod.rs b/model/src/id/mod.rs index 45309c7a56a..98b0715c306 100644 --- a/model/src/id/mod.rs +++ b/model/src/id/mod.rs @@ -32,7 +32,7 @@ //! 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::::new_checked(123).expect("non zero id"); +//! let guild_id = Id::::new(123); //! let role_id = guild_id.cast::(); //! //! assert_eq!(guild_id.get(), role_id.get()); @@ -113,7 +113,7 @@ impl Id { if let Some(id) = Self::new_checked(n) { id } else { - panic!("value passed to `Id::new_checked` is 0"); + panic!("value passed to `Id::new` is zero"); } } @@ -162,13 +162,9 @@ impl Id { /// ``` /// use twilight_model::id::{marker::ChannelMarker, Id}; /// - /// # fn try_main() -> Option<()> { - /// let channel_id = Id::::new_checked(7)?; + /// let channel_id = Id::::new(7); /// /// assert_eq!(7, channel_id.get()); - /// # Some(()) } - /// # - /// # fn main() { try_main().unwrap(); } /// ``` pub const fn get(self) -> u64 { self.value.get() @@ -183,7 +179,7 @@ impl Id { /// ``` /// use twilight_model::id::{marker::{GuildMarker, RoleMarker}, Id}; /// - /// let role_id: Id = Id::new_checked(1).expect("non zero id"); + /// let role_id: Id = Id::new(1); /// /// let guild_id: Id = role_id.cast(); /// assert_eq!(1, guild_id.get()); @@ -206,7 +202,7 @@ impl Id { /// id::{marker::UserMarker, Id}, /// }; /// - /// let id = Id::::new_checked(105484726235607040).expect("non zero"); + /// let id = Id::::new(105484726235607040); /// /// assert_eq!(id.timestamp(), 1445219918546); /// @@ -559,14 +555,14 @@ mod tests { /// Test that casting IDs maintains the original value. #[test] fn test_cast() { - let id = Id::::new_checked(123).expect("non zero"); + let id = Id::::new(123); assert_eq!(123_u64, id.cast::()); } #[test] fn test_timestamp() { let expected: i64 = 1_445_219_918_546; - let id = Id::::new_checked(105_484_726_235_607_040).expect("non zero"); + let id = Id::::new(105_484_726_235_607_040); assert_eq!(expected, id.timestamp()) } @@ -574,7 +570,7 @@ mod tests { #[test] fn test_worker_id() { let expected: u8 = 8; - let id = Id::::new_checked(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()) } @@ -582,7 +578,7 @@ mod tests { #[test] fn test_process_id() { let expected: u8 = 1; - let id = Id::::new_checked(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()) } @@ -590,7 +586,7 @@ mod tests { #[test] fn test_increment() { let expected: u16 = 40; - let id = Id::::new_checked(762_022_344_856_174_632).expect("non zero"); + let id = Id::::new(762_022_344_856_174_632); assert_eq!(expected, id.increment()) } @@ -598,7 +594,7 @@ mod tests { /// Test that debugging IDs formats the generic and value as a newtype. #[test] fn test_debug() { - let id = Id::::new_checked(114_941_315_417_899_012).expect("non zero"); + let id = Id::::new(114_941_315_417_899_012); assert_eq!("Id(114941315417899012)", format!("{:?}", id)); } @@ -606,7 +602,7 @@ mod tests { /// Test that display formatting an ID formats the value. #[test] fn test_display() { - let id = Id::::new_checked(114_941_315_417_899_012).expect("non zero"); + let id = Id::::new(114_941_315_417_899_012); assert_eq!("114941315417899012", id.to_string()); } @@ -614,7 +610,7 @@ mod tests { /// Test that hashing an ID is equivalent to hashing only its inner value. #[test] fn test_hash() { - let id = Id::::new_checked(123).expect("non zero"); + let id = Id::::new(123); let mut id_hasher = DefaultHasher::new(); id.hash(&mut id_hasher); @@ -628,9 +624,9 @@ mod tests { /// Test that IDs are ordered exactly like their inner values. #[test] fn test_ordering() { - let lesser = Id::::new_checked(911_638_235_594_244_096).expect("non zero"); - let center = Id::::new_checked(911_638_263_322_800_208).expect("non zero"); - let greater = Id::::new_checked(911_638_287_939_166_208).expect("non zero"); + let lesser = Id::::new(911_638_235_594_244_096); + let center = Id::::new(911_638_263_322_800_208); + let greater = Id::::new(911_638_287_939_166_208); assert!(center.cmp(&greater).is_lt()); assert!(center.cmp(¢er).is_eq()); @@ -641,224 +637,224 @@ mod tests { #[test] fn test_serde() { serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), ], ); serde_test::assert_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::Str("114941315417899012"), ], ); serde_test::assert_de_tokens( - &Id::::new_checked(114_941_315_417_899_012).expect("non zero"), + &Id::::new(114_941_315_417_899_012), &[ Token::NewtypeStruct { name: "Id" }, Token::U64(114_941_315_417_899_012), diff --git a/model/src/invite/channel.rs b/model/src/invite/channel.rs index ca9907f42ef..958e2c13268 100644 --- a/model/src/invite/channel.rs +++ b/model/src/invite/channel.rs @@ -25,7 +25,7 @@ mod tests { #[test] fn test_invite_channel() { let value = InviteChannel { - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: Some("channel name".to_owned()), kind: ChannelType::GuildText, }; diff --git a/model/src/invite/guild.rs b/model/src/invite/guild.rs index 2bfc1d2325f..25b91263667 100644 --- a/model/src/invite/guild.rs +++ b/model/src/invite/guild.rs @@ -43,7 +43,7 @@ mod tests { description: Some("a description".to_owned()), features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "guild name".to_owned(), splash: Some("splash hash".to_owned()), vanity_url_code: Some("twilight".to_owned()), @@ -52,15 +52,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new_checked(123).expect("non zero"), + channel_id: Id::new(123), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new_checked(456).expect("non zero"), + channel_id: Id::new(456), description: "custom description".to_owned(), - emoji_id: Some(Id::new_checked(789).expect("non zero")), + emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, ], diff --git a/model/src/invite/mod.rs b/model/src/invite/mod.rs index 4fd57220253..e146574f091 100644 --- a/model/src/invite/mod.rs +++ b/model/src/invite/mod.rs @@ -100,7 +100,7 @@ mod tests { approximate_member_count: Some(31), approximate_presence_count: Some(7), channel: Some(InviteChannel { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::Group, name: None, }), @@ -164,7 +164,7 @@ mod tests { approximate_member_count: Some(31), approximate_presence_count: Some(7), channel: Some(InviteChannel { - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::Group, name: None, }), @@ -176,7 +176,7 @@ mod tests { description: Some("a description".to_owned()), features: vec!["a feature".to_owned()], icon: Some("icon hash".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), name: "guild name".to_owned(), splash: Some("splash hash".to_owned()), vanity_url_code: Some("twilight".to_owned()), @@ -185,15 +185,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new_checked(123).expect("non zero"), + channel_id: Id::new(123), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new_checked(456).expect("non zero"), + channel_id: Id::new(456), description: "custom description".to_owned(), - emoji_id: Some(Id::new_checked(789).expect("non zero")), + emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, ], @@ -207,7 +207,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -234,7 +234,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), @@ -257,7 +257,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/invite/welcome_screen.rs b/model/src/invite/welcome_screen.rs index 23d9bec81bb..d3da280fc5a 100644 --- a/model/src/invite/welcome_screen.rs +++ b/model/src/invite/welcome_screen.rs @@ -36,15 +36,15 @@ mod tests { description: Some("welcome description".to_owned()), welcome_channels: vec![ WelcomeScreenChannel { - channel_id: Id::new_checked(123).expect("non zero"), + channel_id: Id::new(123), description: "channel description".to_owned(), emoji_id: None, emoji_name: Some("\u{1f352}".to_owned()), }, WelcomeScreenChannel { - channel_id: Id::new_checked(456).expect("non zero"), + channel_id: Id::new(456), description: "custom description".to_owned(), - emoji_id: Some(Id::new_checked(789).expect("non zero")), + emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, ], diff --git a/model/src/oauth/current_application_info/mod.rs b/model/src/oauth/current_application_info/mod.rs index 7c67209c25e..1f272cd4f0e 100644 --- a/model/src/oauth/current_application_info/mod.rs +++ b/model/src/oauth/current_application_info/mod.rs @@ -88,10 +88,10 @@ mod tests { bot_require_code_grant: false, cover_image: Some("cover image hash".to_owned()), description: "a pretty cool application".to_owned(), - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), flags: Some(ApplicationFlags::EMBEDDED), icon: Some("icon hash".to_owned()), - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), name: "cool application".to_owned(), owner: User { accent_color: None, @@ -101,7 +101,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "app dev".to_owned(), @@ -110,17 +110,17 @@ mod tests { system: None, verified: None, }, - primary_sku_id: Some(Id::new_checked(4).expect("non zero")), + primary_sku_id: Some(Id::new(4)), privacy_policy_url: Some("https://privacypolicy".into()), rpc_origins: vec!["one".to_owned()], slug: Some("app slug".to_owned()), summary: "a summary".to_owned(), team: Some(Team { icon: None, - id: Id::new_checked(5).expect("non zero"), + id: Id::new(5), members: Vec::new(), name: "team name".into(), - owner_user_id: Id::new_checked(6).expect("non zero"), + owner_user_id: Id::new(6), }), terms_of_service_url: Some("https://termsofservice".into()), verify_key: "key".to_owned(), diff --git a/model/src/oauth/team/member.rs b/model/src/oauth/team/member.rs index ee0e7f6f818..00a6db47ca4 100644 --- a/model/src/oauth/team/member.rs +++ b/model/src/oauth/team/member.rs @@ -24,7 +24,7 @@ mod tests { let value = TeamMember { membership_state: TeamMembershipState::Accepted, permissions: vec!["*".to_owned()], - team_id: Id::new_checked(1).expect("non zero"), + team_id: Id::new(1), user: User { accent_color: None, avatar: None, @@ -33,7 +33,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "test".to_owned(), diff --git a/model/src/oauth/team/mod.rs b/model/src/oauth/team/mod.rs index 14f0c76e8b6..89e06237160 100644 --- a/model/src/oauth/team/mod.rs +++ b/model/src/oauth/team/mod.rs @@ -43,10 +43,10 @@ mod tests { fn test_team() { let value = Team { icon: Some("hash".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), members: Vec::new(), name: "team name".into(), - owner_user_id: Id::new_checked(2).expect("non zero"), + owner_user_id: Id::new(2), }; serde_test::assert_tokens( diff --git a/model/src/template/mod.rs b/model/src/template/mod.rs index 2531e27eec4..9c26814fd41 100644 --- a/model/src/template/mod.rs +++ b/model/src/template/mod.rs @@ -187,7 +187,7 @@ mod tests { email: None, discriminator: 1111, flags: None, - id: Id::new_checked(100).expect("non zero"), + id: Id::new(100), locale: None, mfa_enabled: None, name: "username".into(), @@ -196,7 +196,7 @@ mod tests { system: None, verified: None, }, - creator_id: Id::new_checked(100).expect("non zero"), + creator_id: Id::new(100), description: Some("description".into()), is_dirty: None, name: "name".into(), @@ -206,7 +206,7 @@ mod tests { channels: vec![ GuildChannel::Category(CategoryChannel { guild_id: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), kind: ChannelType::GuildCategory, name: "Text Channels".into(), permission_overwrites: vec![], @@ -214,26 +214,26 @@ mod tests { }), GuildChannel::Text(TextChannel { guild_id: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, name: "general".into(), nsfw: false, - parent_id: Some(Id::new_checked(1).expect("non zero")), + parent_id: Some(Id::new(1)), permission_overwrites: vec![ PermissionOverwrite { allow: Permissions::from_bits(0).unwrap(), deny: Permissions::from_bits(2048).unwrap(), kind: PermissionOverwriteType::Role( - Id::new_checked(1).expect("non zero"), + Id::new(1), ), }, PermissionOverwrite { allow: Permissions::from_bits(2048).unwrap(), deny: Permissions::from_bits(0).unwrap(), kind: PermissionOverwriteType::Role( - Id::new_checked(2).expect("non zero"), + Id::new(2), ), }, ], @@ -243,7 +243,7 @@ mod tests { }), GuildChannel::Category(CategoryChannel { guild_id: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), kind: ChannelType::GuildCategory, name: "Voice Channels".into(), permission_overwrites: vec![], @@ -252,10 +252,10 @@ mod tests { GuildChannel::Voice(VoiceChannel { bitrate: 64000, guild_id: None, - id: Id::new_checked(4).expect("non zero"), + id: Id::new(4), kind: ChannelType::GuildVoice, name: "General".into(), - parent_id: Some(Id::new_checked(3).expect("non zero")), + parent_id: Some(Id::new(3)), permission_overwrites: vec![], rtc_region: None, position: 0, @@ -273,7 +273,7 @@ mod tests { TemplateRole { color: 0, hoist: false, - id: Id::new_checked(200).expect("non zero"), + id: Id::new(200), mentionable: false, name: "@everyone".into(), permissions: Permissions::CREATE_INVITE @@ -295,7 +295,7 @@ mod tests { TemplateRole { color: 0, hoist: false, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), mentionable: false, name: "new role".into(), permissions: Permissions::CREATE_INVITE @@ -316,10 +316,10 @@ mod tests { }, ], system_channel_flags: SystemChannelFlags::empty(), - system_channel_id: Some(Id::new_checked(2).expect("non zero")), + system_channel_id: Some(Id::new(2)), verification_level: VerificationLevel::None, }, - source_guild_id: Id::new_checked(200).expect("non zero"), + source_guild_id: Id::new(200), updated_at, usage_count: 0, }; diff --git a/model/src/user/current_user.rs b/model/src/user/current_user.rs index 51d8a6c9dd9..af91ec03a8f 100644 --- a/model/src/user/current_user.rs +++ b/model/src/user/current_user.rs @@ -178,7 +178,7 @@ mod tests { bot: true, discriminator: 9999, email: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), mfa_enabled: true, name: "test name".to_owned(), verified: Some(true), @@ -207,7 +207,7 @@ mod tests { bot: true, discriminator: 9999, email: Some("test@example.com".to_owned()), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), mfa_enabled: true, name: "test name".to_owned(), verified: Some(true), diff --git a/model/src/user/current_user_guild.rs b/model/src/user/current_user_guild.rs index e95b594fe29..bf9959d6784 100644 --- a/model/src/user/current_user_guild.rs +++ b/model/src/user/current_user_guild.rs @@ -42,7 +42,7 @@ mod tests { fn test_current_user_guild() { // The example partial guild from the discord docs let value = CurrentUserGuild { - id: Id::new_checked(80_351_110_224_678_912).expect("non zero"), + id: Id::new(80_351_110_224_678_912), name: "abcd".to_owned(), icon: Some("8342729096ea3675442027381ff50dfe".to_owned()), owner: true, diff --git a/model/src/user/mod.rs b/model/src/user/mod.rs index 5c51d3bf989..d28d1b98d01 100644 --- a/model/src/user/mod.rs +++ b/model/src/user/mod.rs @@ -305,7 +305,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), @@ -335,7 +335,7 @@ mod tests { discriminator: 1, email: Some("address@example.com".to_owned()), flags: Some(UserFlags::PREMIUM_EARLY_SUPPORTER | UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "test".to_owned(), diff --git a/model/src/user/profile.rs b/model/src/user/profile.rs index 28a8beccf88..82c04d6cbc4 100644 --- a/model/src/user/profile.rs +++ b/model/src/user/profile.rs @@ -109,7 +109,7 @@ mod tests { discriminator: 4, email: Some("email@example.com".to_owned()), flags: Some(UserFlags::VERIFIED_DEVELOPER), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), locale: Some("en-us".to_owned()), mfa_enabled: Some(true), name: "user name".to_owned(), diff --git a/model/src/voice/voice_state.rs b/model/src/voice/voice_state.rs index 2e321c36e30..05c5f7f9cf2 100644 --- a/model/src/voice/voice_state.rs +++ b/model/src/voice/voice_state.rs @@ -149,7 +149,7 @@ impl<'de> Visitor<'de> for VoiceStateVisitor { } let deserializer = - OptionalMemberDeserializer::new(Id::new_checked(1).expect("non zero")); + OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } @@ -302,9 +302,9 @@ mod tests { #[test] fn test_voice_state() { let value = VoiceState { - channel_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Some(Id::new(1)), deaf: false, - guild_id: Some(Id::new_checked(2).expect("non zero")), + guild_id: Some(Id::new(2)), member: None, mute: true, self_deaf: false, @@ -313,7 +313,7 @@ mod tests { session_id: "a".to_owned(), suppress: true, token: None, - user_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new(3), request_to_speak_timestamp: None, }; @@ -364,14 +364,14 @@ mod tests { let request_to_speak_timestamp = Timestamp::from_str("2021-04-21T22:16:50.000000+00:00")?; let value = VoiceState { - channel_id: Some(Id::new_checked(1).expect("non zero")), + channel_id: Some(Id::new(1)), deaf: false, - guild_id: Some(Id::new_checked(2).expect("non zero")), + guild_id: Some(Id::new(2)), member: Some(Member { avatar: None, communication_disabled_until: None, deaf: false, - guild_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(2), joined_at, mute: true, nick: Some("twilight".to_owned()), @@ -386,7 +386,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -403,7 +403,7 @@ mod tests { session_id: "a".to_owned(), suppress: true, token: Some("abc".to_owned()), - user_id: Id::new_checked(3).expect("non zero"), + user_id: Id::new(3), request_to_speak_timestamp: Some(request_to_speak_timestamp), }; diff --git a/standby/README.md b/standby/README.md index e1639d3f211..12498710825 100644 --- a/standby/README.md +++ b/standby/README.md @@ -59,7 +59,7 @@ use twilight_standby::Standby; let standby = Standby::new(); -let channel_id = Id::new_checked(123).expect("non zero"); +let channel_id = Id::new(123); let message = standby.wait_for_message(channel_id, |event: &MessageCreate| { event.author.id.get() == 456 && event.content == "test" diff --git a/standby/src/lib.rs b/standby/src/lib.rs index 52431ffc07f..b559a575961 100644 --- a/standby/src/lib.rs +++ b/standby/src/lib.rs @@ -58,7 +58,7 @@ //! //! let standby = Standby::new(); //! -//! let channel_id = Id::new_checked(123).expect("non zero"); +//! let channel_id = Id::new(123); //! //! let message = standby.wait_for_message(channel_id, |event: &MessageCreate| { //! event.author.id.get() == 456 && event.content == "test" @@ -348,7 +348,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let guild_id = Id::new_checked(123).expect("non zero"); + /// let guild_id = Id::new(123); /// /// let reaction = standby.wait_for(guild_id, |event: &Event| { /// event.kind() == EventType::BanAdd @@ -398,7 +398,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let guild_id = Id::new_checked(123).expect("non zero"); + /// let guild_id = Id::new(123); /// /// let mut stream = standby.wait_for_stream(guild_id, |event: &Event| { /// event.kind() == EventType::BanAdd @@ -574,8 +574,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let author_id = Id::new_checked(456).expect("non zero"); - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let author_id = Id::new(456); + /// let channel_id = Id::new(123); /// /// let message = standby.wait_for_message(channel_id, move |event: &MessageCreate| { /// event.author.id == author_id && event.content == "test" @@ -625,8 +625,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let author_id = Id::new_checked(456).expect("non zero"); - /// let channel_id = Id::new_checked(123).expect("non zero"); + /// let author_id = Id::new(456); + /// let channel_id = Id::new(123); /// /// let mut messages = standby.wait_for_message_stream(channel_id, move |event: &MessageCreate| { /// event.author.id == author_id && event.content == "test" @@ -678,8 +678,8 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let message_id = Id::new_checked(123).expect("non zero"); - /// let user_id = Id::new_checked(456).expect("non zero"); + /// let message_id = Id::new(123); + /// let user_id = Id::new(456); /// /// let reaction = standby.wait_for_reaction(message_id, move |event: &ReactionAdd| { /// event.user_id == user_id @@ -729,7 +729,7 @@ impl Standby { /// /// let standby = Standby::new(); /// - /// let message_id = Id::new_checked(123).expect("non zero"); + /// let message_id = Id::new(123); /// /// let mut reactions = standby.wait_for_reaction_stream(message_id, |event: &ReactionAdd| { /// matches!(&event.emoji, ReactionType::Unicode { name } if name == "🤠") @@ -781,10 +781,10 @@ impl Standby { /// use twilight_standby::Standby; /// /// let standby = Standby::new(); - /// let message_id = Id::new_checked(123).expect("non zero"); + /// let message_id = Id::new(123); /// /// let component = standby.wait_for_component(message_id, |event: &MessageComponentInteraction| { - /// event.author_id() == Some(Id::new_checked(456).expect("non zero")) + /// event.author_id() == Some(Id::new(456)) /// }).await?; /// # Ok(()) } /// ``` @@ -826,7 +826,7 @@ impl Standby { /// use twilight_standby::Standby; /// /// let standby = Standby::new(); - /// let message_id = Id::new_checked(123).expect("non zero"); + /// let message_id = Id::new(123); /// /// let mut components = standby.wait_for_component_stream(message_id, |event: &MessageComponentInteraction| { /// event.data.custom_id == "Click".to_string() @@ -1243,7 +1243,7 @@ mod tests { fn message() -> Message { Message { - id: Id::new_checked(3).expect("non zero"), + id: Id::new(3), activity: None, application: None, application_id: None, @@ -1256,7 +1256,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -1265,13 +1265,13 @@ mod tests { system: None, verified: None, }, - channel_id: Id::new_checked(1).expect("non zero"), + channel_id: Id::new(1), components: Vec::new(), content: "test".to_owned(), edited_timestamp: None, embeds: Vec::new(), flags: None, - guild_id: Some(Id::new_checked(4).expect("non zero")), + guild_id: Some(Id::new(4)), interaction: None, kind: MessageType::Regular, member: None, @@ -1293,28 +1293,28 @@ mod tests { fn reaction() -> Reaction { Reaction { - channel_id: Id::new_checked(2).expect("non zero"), + channel_id: Id::new(2), emoji: ReactionType::Unicode { name: "🍎".to_owned(), }, - guild_id: Some(Id::new_checked(1).expect("non zero")), + guild_id: Some(Id::new(1)), member: None, - message_id: Id::new_checked(4).expect("non zero"), - user_id: Id::new_checked(3).expect("non zero"), + message_id: Id::new(4), + user_id: Id::new(3), } } fn button() -> MessageComponentInteraction { MessageComponentInteraction { - application_id: Id::new_checked(1).expect("non zero"), - channel_id: Id::new_checked(2).expect("non zero"), + application_id: Id::new(1), + channel_id: Id::new(2), data: MessageComponentInteractionData { custom_id: String::from("Click"), component_type: ComponentType::Button, values: vec![], }, - guild_id: Some(Id::new_checked(3).expect("non zero")), - id: Id::new_checked(4).expect("non zero"), + guild_id: Some(Id::new(3)), + id: Id::new(4), kind: InteractionType::MessageComponent, member: None, message: message(), @@ -1327,7 +1327,7 @@ mod tests { discriminator: 1, email: None, flags: None, - id: Id::new_checked(2).expect("non zero"), + id: Id::new(2), locale: None, mfa_enabled: None, name: "twilight".to_owned(), @@ -1344,7 +1344,7 @@ mod tests { #[tokio::test] async fn test_dropped() { let standby = Standby::new(); - let guild_id = Id::new_checked(1).expect("non zero"); + let guild_id = Id::new(1); { let _rx = standby.wait_for(guild_id, move |_: &Event| false); @@ -1352,7 +1352,7 @@ mod tests { let results = standby.process(&Event::RoleDelete(RoleDelete { guild_id, - role_id: Id::new_checked(2).expect("non zero"), + role_id: Id::new(2), })); assert_eq!(1, results.dropped()); @@ -1369,8 +1369,8 @@ mod tests { } let standby = Standby::new(); - let guild_id_one = Id::new_checked(1).expect("non zero"); - let guild_id_two = Id::new_checked(2).expect("non zero"); + let guild_id_one = Id::new(1); + let guild_id_two = Id::new(2); let _one = standby.wait_for(guild_id_one, move |event: &Event| { check(event, guild_id_one) }); @@ -1382,8 +1382,8 @@ mod tests { }); let results = standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), })); assert_eq!(0, results.dropped()); @@ -1396,13 +1396,13 @@ mod tests { #[tokio::test] async fn test_sent() { let standby = Standby::new(); - let guild_id = Id::new_checked(1).expect("non zero"); + let guild_id = Id::new(1); let _rx = standby.wait_for_stream(guild_id, move |_: &Event| true); let results = standby.process(&Event::RoleDelete(RoleDelete { guild_id, - role_id: Id::new_checked(2).expect("non zero"), + role_id: Id::new(2), })); assert_eq!(0, results.dropped()); @@ -1415,19 +1415,19 @@ mod tests { async fn test_wait_for() { let standby = Standby::new(); let wait = standby.wait_for( - Id::new_checked(1).expect("non zero"), + Id::new(1), |event: &Event| matches!(event, Event::RoleDelete(e) if e.guild_id.get() == 1), ); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), })); assert_eq!( wait.await.unwrap(), Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), }) ); assert!(standby.guilds.is_empty()); @@ -1438,37 +1438,37 @@ mod tests { async fn test_wait_for_stream() { let standby = Standby::new(); let mut stream = standby.wait_for_stream( - Id::new_checked(1).expect("non zero"), + Id::new(1), |event: &Event| matches!(event, Event::RoleDelete(e) if e.guild_id.get() == 1), ); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), })); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(3).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(3), })); assert_eq!( stream.next().await, Some(Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero") + guild_id: Id::new(1), + role_id: Id::new(2) })) ); assert_eq!( stream.next().await, Some(Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(3).expect("non zero") + guild_id: Id::new(1), + role_id: Id::new(3) })) ); assert!(!standby.guilds.is_empty()); drop(stream); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(4).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(4), })); assert!(standby.guilds.is_empty()); } @@ -1479,7 +1479,7 @@ mod tests { let ready = Ready { application: PartialApplication { flags: ApplicationFlags::empty(), - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), }, guilds: Vec::new(), session_id: String::new(), @@ -1491,7 +1491,7 @@ mod tests { bot: false, discriminator: 1, email: None, - id: Id::new_checked(1).expect("non zero"), + id: Id::new(1), mfa_enabled: true, name: "twilight".to_owned(), verified: Some(false), @@ -1538,10 +1538,9 @@ mod tests { let event = Event::MessageCreate(Box::new(MessageCreate(message))); let standby = Standby::new(); - let wait = standby.wait_for_message( - Id::new_checked(1).expect("non zero"), - |message: &MessageCreate| message.author.id.get() == 2, - ); + let wait = standby.wait_for_message(Id::new(1), |message: &MessageCreate| { + message.author.id.get() == 2 + }); standby.process(&event); assert_eq!(3, wait.await.map(|msg| msg.id.get()).unwrap()); @@ -1553,10 +1552,7 @@ mod tests { #[tokio::test] async fn test_wait_for_message_stream() { let standby = Standby::new(); - let mut stream = standby.wait_for_message_stream( - Id::new_checked(1).expect("non zero"), - |_: &MessageCreate| true, - ); + let mut stream = standby.wait_for_message_stream(Id::new(1), |_: &MessageCreate| true); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); standby.process(&Event::MessageCreate(Box::new(MessageCreate(message())))); @@ -1574,15 +1570,14 @@ mod tests { let event = Event::ReactionAdd(Box::new(ReactionAdd(reaction()))); let standby = Standby::new(); - let wait = standby.wait_for_reaction( - Id::new_checked(4).expect("non zero"), - |reaction: &ReactionAdd| reaction.user_id.get() == 3, - ); + let wait = standby.wait_for_reaction(Id::new(4), |reaction: &ReactionAdd| { + reaction.user_id.get() == 3 + }); standby.process(&event); assert_eq!( - Id::new_checked(3).expect("non zero"), + Id::new(3), wait.await.map(|reaction| reaction.user_id).unwrap() ); assert!(standby.reactions.is_empty()); @@ -1593,10 +1588,7 @@ mod tests { #[tokio::test] async fn test_wait_for_reaction_stream() { let standby = Standby::new(); - let mut stream = standby - .wait_for_reaction_stream(Id::new_checked(4).expect("non zero"), |_: &ReactionAdd| { - true - }); + let mut stream = standby.wait_for_reaction_stream(Id::new(4), |_: &ReactionAdd| true); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); @@ -1617,17 +1609,15 @@ mod tests { ))); let standby = Standby::new(); - let wait = standby.wait_for_component( - Id::new_checked(3).expect("non zero"), - |button: &MessageComponentInteraction| { - button.author_id() == Some(Id::new_checked(2).expect("non zero")) - }, - ); + let wait = standby + .wait_for_component(Id::new(3), |button: &MessageComponentInteraction| { + button.author_id() == Some(Id::new(2)) + }); standby.process(&event); assert_eq!( - Some(Id::new_checked(2).expect("non zero")), + Some(Id::new(2)), wait.await.map(|button| button.author_id()).unwrap() ); assert!(standby.components.is_empty()); @@ -1636,10 +1626,8 @@ mod tests { #[tokio::test] async fn test_wait_for_component_stream() { let standby = Standby::new(); - let mut stream = standby.wait_for_component_stream( - Id::new_checked(3).expect("non zero"), - |_: &MessageComponentInteraction| true, - ); + let mut stream = + standby.wait_for_component_stream(Id::new(3), |_: &MessageComponentInteraction| true); standby.process(&Event::InteractionCreate(Box::new(InteractionCreate( Interaction::MessageComponent(Box::new(button())), )))); @@ -1690,13 +1678,13 @@ mod tests { // generic event handler gets other guild events let wait = standby.wait_for_event(|event: &Event| event.kind() == EventType::RoleDelete); standby.process(&Event::RoleDelete(RoleDelete { - guild_id: Id::new_checked(1).expect("non zero"), - role_id: Id::new_checked(2).expect("non zero"), + guild_id: Id::new(1), + role_id: Id::new(2), })); assert!(matches!(wait.await, Ok(Event::RoleDelete(_)))); // guild event handler gets message creates or reaction events - let wait = standby.wait_for(Id::new_checked(1).expect("non zero"), |event: &Event| { + let wait = standby.wait_for(Id::new(1), |event: &Event| { event.kind() == EventType::ReactionAdd }); standby.process(&Event::ReactionAdd(Box::new(ReactionAdd(reaction())))); diff --git a/util/src/builder/command.rs b/util/src/builder/command.rs index ffdfd2a506c..b25791a5ab8 100644 --- a/util/src/builder/command.rs +++ b/util/src/builder/command.rs @@ -55,7 +55,7 @@ impl CommandBuilder { kind, name, options: Vec::new(), - version: Id::new_checked(1).expect("non zero"), + version: Id::new(1), }) } @@ -817,7 +817,7 @@ mod tests { ]), }), ]), - version: Id::new_checked(1).expect("non zero"), + version: Id::new(1), }; assert_eq!(command, command_manual); diff --git a/util/src/link/webhook.rs b/util/src/link/webhook.rs index 7c9e1eb161f..44f1e4e616f 100644 --- a/util/src/link/webhook.rs +++ b/util/src/link/webhook.rs @@ -87,7 +87,7 @@ pub enum WebhookParseErrorType { /// let url = "https://canary.discord.com/api/webhooks/794590023369752587/tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"; /// /// let (id, token) = webhook::parse(url)?; -/// assert_eq!(Id::new_checked(794590023369752587).expect("non zero"), id); +/// assert_eq!(Id::new(794590023369752587), id); /// assert_eq!( /// Some("tjxHaPHLKp9aEdSwJuLeHhHHGEqIxt1aay4I67FOP9uzsYEWmj0eJmDn-2ZvCYLyOb_K"), /// token, @@ -105,7 +105,7 @@ pub enum WebhookParseErrorType { /// let url = "https://canary.discord.com/api/webhooks/794590023369752587"; /// /// let (id, token) = webhook::parse(url)?; -/// assert_eq!(Id::new_checked(794590023369752587).expect("non zero"), id); +/// assert_eq!(Id::new(794590023369752587), id); /// assert!(token.is_none()); /// # Ok(()) } /// ``` @@ -171,13 +171,13 @@ mod tests { #[test] fn test_parse_no_token() { assert_eq!( - (Id::new_checked(123).expect("non zero"), None), + (Id::new(123), None), super::parse("https://discord.com/api/webhooks/123").unwrap(), ); // There's a / after the ID signifying another segment, but the token // ends up being None. assert_eq!( - (Id::new_checked(123).expect("non zero"), None), + (Id::new(123), None), super::parse("https://discord.com/api/webhooks/123").unwrap(), ); assert!(super::parse("https://discord.com/api/webhooks/123/") @@ -190,24 +190,24 @@ mod tests { fn test_parse_with_token() { assert_eq!( super::parse("https://discord.com/api/webhooks/456/token").unwrap(), - (Id::new_checked(456).expect("non zero"), Some("token")), + (Id::new(456), Some("token")), ); // The value of the segment(s) after the token are ignored. assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/github").unwrap(), - (Id::new_checked(456).expect("non zero"), Some("token")), + (Id::new(456), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/slack").unwrap(), - (Id::new_checked(456).expect("non zero"), Some("token")), + (Id::new(456), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/randomsegment").unwrap(), - (Id::new_checked(456).expect("non zero"), Some("token")), + (Id::new(456), Some("token")), ); assert_eq!( super::parse("https://discord.com/api/webhooks/456/token/one/two/three").unwrap(), - (Id::new_checked(456).expect("non zero"), Some("token")), + (Id::new(456), Some("token")), ); } diff --git a/util/src/permission_calculator/mod.rs b/util/src/permission_calculator/mod.rs index ec0fb5db335..e82aafe3fdf 100644 --- a/util/src/permission_calculator/mod.rs +++ b/util/src/permission_calculator/mod.rs @@ -41,8 +41,8 @@ //! id::Id, //! }; //! -//! let guild_id = Id::new_checked(1).expect("non zero"); -//! let user_id = Id::new_checked(3).expect("non zero"); +//! let guild_id = Id::new(1); +//! let user_id = Id::new(3); //! //! // Guild-level @everyone role that, by default, allows everyone to view //! // channels. @@ -53,7 +53,7 @@ //! let member_roles = &[ //! // Guild-level permission that grants members with the role the Send //! // Messages permission. -//! (Id::new_checked(2).expect("non zero"), Permissions::SEND_MESSAGES), +//! (Id::new(2), Permissions::SEND_MESSAGES), //! ]; //! //! let channel_overwrites = &[ @@ -62,7 +62,7 @@ //! PermissionOverwrite { //! allow: Permissions::ADD_REACTIONS | Permissions::EMBED_LINKS, //! deny: Permissions::empty(), -//! kind: PermissionOverwriteType::Role(Id::new_checked(1).expect("non zero")), +//! kind: PermissionOverwriteType::Role(Id::new(1)), //! }, //! // Member is denied the Send Messages permission. //! PermissionOverwrite { @@ -534,8 +534,8 @@ mod tests { #[test] fn test_owner_is_admin() { - let guild_id = Id::new_checked(1).expect("non zero"); - let user_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let user_id = Id::new(2); let everyone_role = Permissions::SEND_MESSAGES; let roles = &[]; @@ -549,10 +549,10 @@ mod tests { // implicitly denies all other permissions. #[test] fn test_view_channel_deny_implicit() { - let guild_id = Id::new_checked(1).expect("non zero"); - let user_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let user_id = Id::new(2); let everyone_role = Permissions::MENTION_EVERYONE | Permissions::SEND_MESSAGES; - let roles = &[(Id::new_checked(3).expect("non zero"), Permissions::empty())]; + let roles = &[(Id::new(3), Permissions::empty())]; { // First, test when it's denied for an overwrite on a role the user @@ -560,7 +560,7 @@ mod tests { let overwrites = &[PermissionOverwrite { allow: Permissions::SEND_TTS_MESSAGES, deny: Permissions::VIEW_CHANNEL, - kind: PermissionOverwriteType::Role(Id::new_checked(3).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(3)), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -574,7 +574,7 @@ mod tests { let overwrites = &[PermissionOverwrite { allow: Permissions::SEND_TTS_MESSAGES, deny: Permissions::VIEW_CHANNEL, - kind: PermissionOverwriteType::Member(Id::new_checked(2).expect("non zero")), + kind: PermissionOverwriteType::Member(Id::new(2)), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -586,11 +586,11 @@ mod tests { #[test] fn test_remove_text_and_stage_perms_when_voice() { - let guild_id = Id::new_checked(1).expect("non zero"); - let user_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let user_id = Id::new(2); let everyone_role = Permissions::CONNECT; let roles = &[( - Id::new_checked(3).expect("non zero"), + Id::new(3), Permissions::SEND_MESSAGES, )]; @@ -602,11 +602,11 @@ mod tests { #[test] fn test_remove_audio_perms_when_text() { - let guild_id = Id::new_checked(1).expect("non zero"); - let user_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let user_id = Id::new(2); let everyone_role = Permissions::CONNECT; let roles = &[( - Id::new_checked(3).expect("non zero"), + Id::new(3), Permissions::SEND_MESSAGES, )]; @@ -622,17 +622,17 @@ mod tests { // send related permissions. #[test] fn test_deny_send_messages_removes_related() { - let guild_id = Id::new_checked(1).expect("non zero"); - let user_id = Id::new_checked(2).expect("non zero"); + let guild_id = Id::new(1); + let user_id = Id::new(2); let everyone_role = Permissions::MANAGE_MESSAGES | Permissions::EMBED_LINKS | Permissions::MENTION_EVERYONE; - let roles = &[(Id::new_checked(3).expect("non zero"), Permissions::empty())]; + let roles = &[(Id::new(3), Permissions::empty())]; // First, test when it's denied for an overwrite on a role the user has. let overwrites = &[PermissionOverwrite { allow: Permissions::ATTACH_FILES, deny: Permissions::SEND_MESSAGES, - kind: PermissionOverwriteType::Role(Id::new_checked(3).expect("non zero")), + kind: PermissionOverwriteType::Role(Id::new(3)), }]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) @@ -646,12 +646,12 @@ mod tests { #[test] fn test_admin() { let member_roles = &[( - Id::new_checked(3).expect("non zero"), + Id::new(3), Permissions::ADMINISTRATOR, )]; let calc = PermissionCalculator::new( - Id::new_checked(1).expect("non zero"), - Id::new_checked(2).expect("non zero"), + Id::new(1), + Id::new(2), Permissions::empty(), member_roles, ); @@ -682,8 +682,8 @@ mod tests { for kind in CHANNEL_TYPES { let calc = PermissionCalculator::new( - Id::new_checked(1).expect("non zero"), - Id::new_checked(2).expect("non zero"), + Id::new(1), + Id::new(2), everyone, &[], ); diff --git a/validate/src/command.rs b/validate/src/command.rs index 8f861671142..e7ae11d6086 100644 --- a/validate/src/command.rs +++ b/validate/src/command.rs @@ -374,15 +374,15 @@ mod tests { #[test] fn test_command() { let valid_command = Command { - application_id: Some(Id::new_checked(1).expect("non zero")), + application_id: Some(Id::new(1)), default_permission: None, description: "a".repeat(100), - guild_id: Some(Id::new_checked(2).expect("non zero")), - id: Some(Id::new_checked(3).expect("non zero")), + guild_id: Some(Id::new(2)), + id: Some(Id::new(3)), kind: CommandType::ChatInput, name: "b".repeat(32), options: Vec::new(), - version: Id::new_checked(4).expect("non zero"), + version: Id::new(4), }; assert!(command(&valid_command).is_ok()); From 29e294938ff5cd8aff5485c1107848b88eef232f Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:28:25 -0500 Subject: [PATCH 07/13] clippy Signed-off-by: Zeyla Hellyer --- .../request/application/command/set_command_permissions.rs | 6 +++--- .../request/application/interaction/get_followup_message.rs | 4 ++-- http/src/request/guild/create_guild/builder.rs | 4 ++-- http/src/request/guild/member/update_guild_member.rs | 4 ++-- http/src/routing/route_display.rs | 2 +- model/src/application/interaction/message_component/mod.rs | 2 +- model/src/channel/mod.rs | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/http/src/request/application/command/set_command_permissions.rs b/http/src/request/application/command/set_command_permissions.rs index 8c1c2af957f..f5cef6bd0f9 100644 --- a/http/src/request/application/command/set_command_permissions.rs +++ b/http/src/request/application/command/set_command_permissions.rs @@ -76,7 +76,7 @@ impl SortedCommand<'_> { /// Create a new default sorted command with no configured permissions. /// /// The ID of the command is `u64::MAX`. - fn new() -> Self { + const fn new() -> Self { Self { count: 0, id: Id::new(u64::MAX), @@ -230,11 +230,11 @@ mod tests { CommandValidationErrorType, GUILD_COMMAND_LIMIT, GUILD_COMMAND_PERMISSION_LIMIT, }; - fn application_id() -> Id { + const fn application_id() -> Id { Id::new(1) } - fn guild_id() -> Id { + const fn guild_id() -> Id { Id::new(2) } diff --git a/http/src/request/application/interaction/get_followup_message.rs b/http/src/request/application/interaction/get_followup_message.rs index accad6cbeb6..d545252af8b 100644 --- a/http/src/request/application/interaction/get_followup_message.rs +++ b/http/src/request/application/interaction/get_followup_message.rs @@ -105,11 +105,11 @@ mod tests { fn test_request() -> Result<(), Box> { const TOKEN: &str = "token"; - fn application_id() -> Id { + const fn application_id() -> Id { Id::new(1) } - fn message_id() -> Id { + const fn message_id() -> Id { Id::new(2) } diff --git a/http/src/request/guild/create_guild/builder.rs b/http/src/request/guild/create_guild/builder.rs index 636b14c4540..2e7d0ef2da3 100644 --- a/http/src/request/guild/create_guild/builder.rs +++ b/http/src/request/guild/create_guild/builder.rs @@ -83,12 +83,12 @@ impl RoleFieldsBuilder { /// [`color`]: Self::color pub const COLOR_MAXIMUM: u32 = 0xff_ff_ff; - fn role_id() -> Id { + const fn role_id() -> Id { Id::new(1) } /// Create a new default role field builder. - pub fn new(name: String) -> Self { + pub const fn new(name: String) -> Self { Self(RoleFields { color: None, hoist: None, diff --git a/http/src/request/guild/member/update_guild_member.rs b/http/src/request/guild/member/update_guild_member.rs index f963348b4a0..00c8f4fec0c 100644 --- a/http/src/request/guild/member/update_guild_member.rs +++ b/http/src/request/guild/member/update_guild_member.rs @@ -203,11 +203,11 @@ mod tests { Id, }; - fn guild_id() -> Id { + const fn guild_id() -> Id { Id::new(1) } - fn user_id() -> Id { + const fn user_id() -> Id { Id::new(1) } diff --git a/http/src/routing/route_display.rs b/http/src/routing/route_display.rs index 0bb5979c273..690e6e811e4 100644 --- a/http/src/routing/route_display.rs +++ b/http/src/routing/route_display.rs @@ -1143,7 +1143,7 @@ mod tests { const TEMPLATE_CODE: &str = "templatecode"; const USER_ID: u64 = 11; - fn emoji() -> RequestReactionType<'static> { + const fn emoji() -> RequestReactionType<'static> { RequestReactionType::Custom { id: Id::new(EMOJI_ID), name: None, diff --git a/model/src/application/interaction/message_component/mod.rs b/model/src/application/interaction/message_component/mod.rs index 2417656b241..59a9bb72623 100644 --- a/model/src/application/interaction/message_component/mod.rs +++ b/model/src/application/interaction/message_component/mod.rs @@ -136,7 +136,7 @@ mod tests { #[test] fn test_author_id() -> Result<(), TimestampParseError> { - fn user_id() -> Id { + const fn user_id() -> Id { Id::new(7) } diff --git a/model/src/channel/mod.rs b/model/src/channel/mod.rs index b2f3a949577..68536edac55 100644 --- a/model/src/channel/mod.rs +++ b/model/src/channel/mod.rs @@ -770,7 +770,7 @@ mod tests { } } - fn private() -> PrivateChannel { + const fn private() -> PrivateChannel { PrivateChannel { id: Id::new(234), last_message_id: None, From ee9b6f36d2ba809474d14ccdb27bc21daea4fb1a Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:28:34 -0500 Subject: [PATCH 08/13] fmt Signed-off-by: Zeyla Hellyer --- cache/in-memory/src/event/guild.rs | 8 +-- cache/in-memory/src/event/interaction.rs | 22 ++---- cache/in-memory/src/event/message.rs | 18 +---- cache/in-memory/src/event/reaction.rs | 16 ++--- examples/gateway-request-members/src/main.rs | 5 +- .../interaction/delete_followup_message.rs | 7 +- .../request/channel/invite/create_invite.rs | 6 +- .../channel/reaction/create_reaction.rs | 7 +- .../channel/webhook/delete_webhook_message.rs | 7 +- .../channel/webhook/update_webhook_message.rs | 17 ++--- mention/src/parse/iter.rs | 70 ++++--------------- .../message/allowed_mentions/builder.rs | 10 +-- model/src/channel/reaction.rs | 3 +- .../gateway/payload/incoming/member_chunk.rs | 23 ++---- .../payload/incoming/thread_members_update.rs | 4 +- .../gateway/payload/incoming/typing_start.rs | 3 +- .../payload/incoming/unavailable_guild.rs | 4 +- .../payload/incoming/voice_state_update.rs | 5 +- model/src/gateway/presence/mod.rs | 8 +-- model/src/template/mod.rs | 8 +-- model/src/voice/voice_state.rs | 3 +- util/src/permission_calculator/mod.rs | 30 ++------ 22 files changed, 63 insertions(+), 221 deletions(-) diff --git a/cache/in-memory/src/event/guild.rs b/cache/in-memory/src/event/guild.rs index ca2f66b0d68..0ada94d30de 100644 --- a/cache/in-memory/src/event/guild.rs +++ b/cache/in-memory/src/event/guild.rs @@ -329,13 +329,9 @@ mod tests { let cache = InMemoryCache::new(); cache.cache_guild(guild); - let channel = cache - .guild_channel(Id::new(111)) - .unwrap(); + let channel = cache.guild_channel(Id::new(111)).unwrap(); - let thread = cache - .guild_channel(Id::new(222)) - .unwrap(); + let thread = cache.guild_channel(Id::new(222)).unwrap(); // The channel was given to the cache without a guild ID, but because // it's part of a guild create, the cache can automatically attach the diff --git a/cache/in-memory/src/event/interaction.rs b/cache/in-memory/src/event/interaction.rs index 2643904812f..9a30ab4314b 100644 --- a/cache/in-memory/src/event/interaction.rs +++ b/cache/in-memory/src/event/interaction.rs @@ -255,38 +255,24 @@ mod tests { ))); { - let guild_members = cache - .guild_members(Id::new(3)) - .unwrap(); + let guild_members = cache.guild_members(Id::new(3)).unwrap(); assert_eq!(guild_members.len(), 2); } { - let member = cache - .member( - Id::new(3), - Id::new(6), - ) - .unwrap(); + let member = cache.member(Id::new(3), Id::new(6)).unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "avatar string"); } { - let member = cache - .member( - Id::new(3), - Id::new(7), - ) - .unwrap(); + let member = cache.member(Id::new(3), Id::new(7)).unwrap(); let user = cache.user(member.user_id).unwrap(); assert_eq!(user.avatar.as_ref().unwrap(), "different avatar"); } { - let guild_roles = cache - .guild_roles(Id::new(3)) - .unwrap(); + let guild_roles = cache.guild_roles(Id::new(3)).unwrap(); assert_eq!(guild_roles.len(), 1); } } diff --git a/cache/in-memory/src/event/message.rs b/cache/in-memory/src/event/message.rs index a48161303e2..950dc162568 100644 --- a/cache/in-memory/src/event/message.rs +++ b/cache/in-memory/src/event/message.rs @@ -210,27 +210,15 @@ mod tests { cache.update(&MessageCreate(msg)); { - let entry = cache - .user_guilds - .get(&Id::new(3)) - .unwrap(); + let entry = cache.user_guilds.get(&Id::new(3)).unwrap(); assert_eq!(entry.value().len(), 1); } assert_eq!( - cache - .member( - Id::new(1), - Id::new(3) - ) - .unwrap() - .user_id, + cache.member(Id::new(1), Id::new(3)).unwrap().user_id, Id::new(3), ); { - let entry = cache - .channel_messages - .get(&Id::new(2)) - .unwrap(); + let entry = cache.channel_messages.get(&Id::new(2)).unwrap(); assert_eq!(entry.value().len(), 2); } diff --git a/cache/in-memory/src/event/reaction.rs b/cache/in-memory/src/event/reaction.rs index 18ed4150bcb..3cbdc9888e8 100644 --- a/cache/in-memory/src/event/reaction.rs +++ b/cache/in-memory/src/event/reaction.rs @@ -125,9 +125,7 @@ mod tests { #[test] fn test_reaction_add() { let cache = test::cache_with_message_and_reactions(); - let msg = cache - .message(Id::new(4)) - .unwrap(); + let msg = cache.message(Id::new(4)).unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -160,9 +158,7 @@ mod tests { user_id: Id::new(5), })); - let msg = cache - .message(Id::new(4)) - .unwrap(); + let msg = cache.message(Id::new(4)).unwrap(); assert_eq!(msg.reactions.len(), 2); @@ -190,9 +186,7 @@ mod tests { guild_id: Some(Id::new(1)), }); - let msg = cache - .message(Id::new(4)) - .unwrap(); + let msg = cache.message(Id::new(4)).unwrap(); assert_eq!(msg.reactions.len(), 0); } @@ -209,9 +203,7 @@ mod tests { message_id: Id::new(4), }); - let msg = cache - .message(Id::new(4)) - .unwrap(); + let msg = cache.message(Id::new(4)).unwrap(); assert_eq!(msg.reactions.len(), 1); diff --git a/examples/gateway-request-members/src/main.rs b/examples/gateway-request-members/src/main.rs index d1345070364..fbc000407a3 100644 --- a/examples/gateway-request-members/src/main.rs +++ b/examples/gateway-request-members/src/main.rs @@ -41,10 +41,7 @@ async fn main() -> Result<(), Box> { // check to make sure you're requesting at most that many: let request = RequestGuildMembers::builder(Id::new(1)) .nonce("requesting two member") - .user_ids(vec![ - Id::new(2), - Id::new(3), - ]) + .user_ids(vec![Id::new(2), Id::new(3)]) .unwrap(); shard.command(&request).await?; diff --git a/http/src/request/application/interaction/delete_followup_message.rs b/http/src/request/application/interaction/delete_followup_message.rs index 82e0dbf1234..4da3dc8c593 100644 --- a/http/src/request/application/interaction/delete_followup_message.rs +++ b/http/src/request/application/interaction/delete_followup_message.rs @@ -94,12 +94,7 @@ mod tests { fn test_request() -> Result<(), Box> { let client = Client::new("token".to_owned()); - let builder = DeleteFollowupMessage::new( - &client, - Id::new(1), - "token", - Id::new(2), - ); + let builder = DeleteFollowupMessage::new(&client, Id::new(1), "token", Id::new(2)); let actual = builder.try_into_request()?; let expected = Request::from_route(&Route::DeleteWebhookMessage { diff --git a/http/src/request/channel/invite/create_invite.rs b/http/src/request/channel/invite/create_invite.rs index c5a56e7e07c..96401b111df 100644 --- a/http/src/request/channel/invite/create_invite.rs +++ b/http/src/request/channel/invite/create_invite.rs @@ -258,8 +258,7 @@ mod tests { #[test] fn test_max_age() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = - CreateInvite::new(&client, Id::new(1)).max_age(0)?; + let mut builder = CreateInvite::new(&client, Id::new(1)).max_age(0)?; assert_eq!(Some(0), builder.fields.max_age); builder = builder.max_age(604_800)?; assert_eq!(Some(604_800), builder.fields.max_age); @@ -271,8 +270,7 @@ mod tests { #[test] fn test_max_uses() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let mut builder = - CreateInvite::new(&client, Id::new(1)).max_uses(0)?; + let mut builder = CreateInvite::new(&client, Id::new(1)).max_uses(0)?; assert_eq!(Some(0), builder.fields.max_uses); builder = builder.max_uses(100)?; assert_eq!(Some(100), builder.fields.max_uses); diff --git a/http/src/request/channel/reaction/create_reaction.rs b/http/src/request/channel/reaction/create_reaction.rs index 9449de4764b..b3252b5a10b 100644 --- a/http/src/request/channel/reaction/create_reaction.rs +++ b/http/src/request/channel/reaction/create_reaction.rs @@ -101,12 +101,7 @@ mod tests { let emoji = RequestReactionType::Unicode { name: "🌃" }; - let builder = CreateReaction::new( - &client, - Id::new(123), - Id::new(456), - &emoji, - ); + let builder = CreateReaction::new(&client, Id::new(123), Id::new(456), &emoji); let actual = builder.try_into_request()?; let expected = Request::from_route(&Route::CreateReaction { diff --git a/http/src/request/channel/webhook/delete_webhook_message.rs b/http/src/request/channel/webhook/delete_webhook_message.rs index 697fef99c72..c93828d0ff9 100644 --- a/http/src/request/channel/webhook/delete_webhook_message.rs +++ b/http/src/request/channel/webhook/delete_webhook_message.rs @@ -116,12 +116,7 @@ mod tests { #[test] fn test_request() { let client = Client::new("token".to_owned()); - let builder = DeleteWebhookMessage::new( - &client, - Id::new(1), - "token", - Id::new(2), - ); + let builder = DeleteWebhookMessage::new(&client, Id::new(1), "token", Id::new(2)); let actual = builder .try_into_request() .expect("failed to create request"); diff --git a/http/src/request/channel/webhook/update_webhook_message.rs b/http/src/request/channel/webhook/update_webhook_message.rs index 349eccb5d10..b32484c6a8b 100644 --- a/http/src/request/channel/webhook/update_webhook_message.rs +++ b/http/src/request/channel/webhook/update_webhook_message.rs @@ -371,17 +371,12 @@ mod tests { #[test] fn test_request() { let client = Client::new("token".to_owned()); - let builder = UpdateWebhookMessage::new( - &client, - Id::new(1), - "token", - Id::new(2), - ) - .content(Some("test")) - .expect("'test' content couldn't be set") - .thread_id(Id::new(3)) - .reason("reason") - .expect("'reason' is not a valid reason"); + let builder = UpdateWebhookMessage::new(&client, Id::new(1), "token", Id::new(2)) + .content(Some("test")) + .expect("'test' content couldn't be set") + .thread_id(Id::new(3)) + .reason("reason") + .expect("'reason' is not a valid reason"); let actual = builder .try_into_request() .expect("failed to create request"); diff --git a/mention/src/parse/iter.rs b/mention/src/parse/iter.rs index 28e019dd3c2..bbac5f12b69 100644 --- a/mention/src/parse/iter.rs +++ b/mention/src/parse/iter.rs @@ -128,10 +128,7 @@ mod tests { #[test] fn test_iter_channel_id() { let mut iter = Id::::iter("<#123>"); - assert_eq!( - Id::new(123), - iter.next().unwrap().0 - ); + assert_eq!(Id::new(123), iter.next().unwrap().0); assert!(iter.next().is_none()); } @@ -139,10 +136,7 @@ mod tests { fn test_iter_multiple_ids() { let buf = "one <@123>two<#456><@789> ----"; let mut iter = Id::::iter(buf); - assert_eq!( - Id::new(123), - iter.next().unwrap().0 - ); + assert_eq!(Id::new(123), iter.next().unwrap().0); let (mention, start, end) = iter.next().unwrap(); assert_eq!(Id::new(789), mention); assert_eq!(19, start); @@ -153,50 +147,26 @@ mod tests { #[test] fn test_iter_emoji_ids() { let mut iter = Id::::iter("some <:name:123> emojis <:emoji:456>"); - assert_eq!( - Id::new(123), - iter.next().unwrap().0 - ); - assert_eq!( - Id::new(456), - iter.next().unwrap().0 - ); + assert_eq!(Id::new(123), iter.next().unwrap().0); + assert_eq!(Id::new(456), iter.next().unwrap().0); assert!(iter.next().is_none()); } #[test] fn test_iter_mention_type() { let mut iter = MentionType::iter("<#12><:name:34><@&56><@!78><@90>"); - assert_eq!( - MentionType::Channel(Id::new(12)), - iter.next().unwrap().0 - ); - assert_eq!( - MentionType::Emoji(Id::new(34)), - iter.next().unwrap().0 - ); - assert_eq!( - MentionType::Role(Id::new(56)), - iter.next().unwrap().0 - ); - assert_eq!( - MentionType::User(Id::new(78)), - iter.next().unwrap().0 - ); - assert_eq!( - MentionType::User(Id::new(90)), - iter.next().unwrap().0 - ); + assert_eq!(MentionType::Channel(Id::new(12)), iter.next().unwrap().0); + assert_eq!(MentionType::Emoji(Id::new(34)), iter.next().unwrap().0); + assert_eq!(MentionType::Role(Id::new(56)), iter.next().unwrap().0); + assert_eq!(MentionType::User(Id::new(78)), iter.next().unwrap().0); + assert_eq!(MentionType::User(Id::new(90)), iter.next().unwrap().0); assert!(iter.next().is_none()); } #[test] fn test_iter_mention_type_with_timestamp() { let mut iter = MentionType::iter("<#12> "); - assert_eq!( - MentionType::Channel(Id::new(12)), - iter.next().unwrap().0 - ); + assert_eq!(MentionType::Channel(Id::new(12)), iter.next().unwrap().0); assert_eq!( MentionType::Timestamp(Timestamp::new(34, None)), iter.next().unwrap().0 @@ -211,14 +181,8 @@ mod tests { #[test] fn test_iter_role_ids() { let mut iter = Id::::iter("some <@&123> roles <@&456>"); - assert_eq!( - Id::new(123), - iter.next().unwrap().0 - ); - assert_eq!( - Id::new(456), - iter.next().unwrap().0 - ); + assert_eq!(Id::new(123), iter.next().unwrap().0); + assert_eq!(Id::new(456), iter.next().unwrap().0); assert!(iter.next().is_none()); } @@ -236,14 +200,8 @@ mod tests { #[test] fn test_iter_user_ids() { let mut iter = Id::::iter("some <@123>users<@456>"); - assert_eq!( - Id::new(123), - iter.next().unwrap().0 - ); - assert_eq!( - Id::new(456), - iter.next().unwrap().0 - ); + assert_eq!(Id::new(123), iter.next().unwrap().0); + assert_eq!(Id::new(456), iter.next().unwrap().0); assert!(iter.next().is_none()); } diff --git a/model/src/channel/message/allowed_mentions/builder.rs b/model/src/channel/message/allowed_mentions/builder.rs index f1e4babfbb8..4c97dff089d 100644 --- a/model/src/channel/message/allowed_mentions/builder.rs +++ b/model/src/channel/message/allowed_mentions/builder.rs @@ -145,10 +145,7 @@ mod tests { fn test_validation() { let value = AllowedMentionsBuilder::new() .users() - .user_ids(vec![ - Id::new(100), - Id::new(200), - ]) + .user_ids(vec![Id::new(100), Id::new(200)]) .roles() .role_ids(vec![Id::new(300)]) .build(); @@ -157,10 +154,7 @@ mod tests { value, AllowedMentions { parse: vec![], - users: vec![ - Id::new(100), - Id::new(200) - ], + users: vec![Id::new(100), Id::new(200)], roles: vec![Id::new(300)], replied_user: false, }, diff --git a/model/src/channel/reaction.rs b/model/src/channel/reaction.rs index e5965d0961c..fea1ef9b1e0 100644 --- a/model/src/channel/reaction.rs +++ b/model/src/channel/reaction.rs @@ -114,8 +114,7 @@ impl<'de> Visitor<'de> for ReactionVisitor { return Err(DeError::duplicate_field("member")); } - let deserializer = - OptionalMemberDeserializer::new(Id::new(1)); + let deserializer = OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } diff --git a/model/src/gateway/payload/incoming/member_chunk.rs b/model/src/gateway/payload/incoming/member_chunk.rs index a7e8520ed72..ae9b8e07dd7 100644 --- a/model/src/gateway/payload/incoming/member_chunk.rs +++ b/model/src/gateway/payload/incoming/member_chunk.rs @@ -123,8 +123,7 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { // Since the guild ID may not be deserialized yet we'll use // a temporary placeholder value and update it with the real // guild ID after all the fields have been deserialized. - let deserializer = - MemberListDeserializer::new(Id::new(1)); + let deserializer = MemberListDeserializer::new(Id::new(1)); members = Some(map.next_value_seed(deserializer)?); } @@ -147,8 +146,7 @@ impl<'de> Visitor<'de> for MemberChunkVisitor { return Err(DeError::duplicate_field("presences")); } - let deserializer = - PresenceListDeserializer::new(Id::new(1)); + let deserializer = PresenceListDeserializer::new(Id::new(1)); presences = Some(map.next_value_seed(deserializer)?); } @@ -341,10 +339,7 @@ mod tests { nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![ - Id::new(6), - Id::new(7), - ], + roles: vec![Id::new(6), Id::new(7)], user: User { id: Id::new(2), accent_color: None, @@ -463,9 +458,7 @@ mod tests { }, guild_id: Id::new(1), status: Status::Online, - user: UserOrId::UserId { - id: Id::new(2), - }, + user: UserOrId::UserId { id: Id::new(2) }, }, Presence { activities: Vec::new(), @@ -476,9 +469,7 @@ mod tests { }, guild_id: Id::new(1), status: Status::Online, - user: UserOrId::UserId { - id: Id::new(3), - }, + user: UserOrId::UserId { id: Id::new(3) }, }, Presence { activities: Vec::new(), @@ -489,9 +480,7 @@ mod tests { }, guild_id: Id::new(1), status: Status::DoNotDisturb, - user: UserOrId::UserId { - id: Id::new(5), - }, + user: UserOrId::UserId { id: Id::new(5) }, }, ]), }; diff --git a/model/src/gateway/payload/incoming/thread_members_update.rs b/model/src/gateway/payload/incoming/thread_members_update.rs index 9d09e347bd7..cabd2181230 100644 --- a/model/src/gateway/payload/incoming/thread_members_update.rs +++ b/model/src/gateway/payload/incoming/thread_members_update.rs @@ -169,9 +169,7 @@ mod tests { }, guild_id: Id::new(2), status: Status::Online, - user: UserOrId::UserId { - id: Id::new(3), - }, + user: UserOrId::UserId { id: Id::new(3) }, }; let join_timestamp = Timestamp::from_str(JOIN_TIMESTAMP).expect("timestamp error"); diff --git a/model/src/gateway/payload/incoming/typing_start.rs b/model/src/gateway/payload/incoming/typing_start.rs index 1550e4c5d26..6983280c3ac 100644 --- a/model/src/gateway/payload/incoming/typing_start.rs +++ b/model/src/gateway/payload/incoming/typing_start.rs @@ -105,8 +105,7 @@ impl<'de> Visitor<'de> for TypingStartVisitor { return Err(DeError::duplicate_field("member")); } - let deserializer = - OptionalMemberDeserializer::new(Id::new(1)); + let deserializer = OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } diff --git a/model/src/gateway/payload/incoming/unavailable_guild.rs b/model/src/gateway/payload/incoming/unavailable_guild.rs index 80cfa3c8fea..ab8faa6dc64 100644 --- a/model/src/gateway/payload/incoming/unavailable_guild.rs +++ b/model/src/gateway/payload/incoming/unavailable_guild.rs @@ -14,9 +14,7 @@ mod tests { #[test] fn test_unavailable_guild() { - let value = UnavailableGuild { - id: Id::new(1), - }; + let value = UnavailableGuild { id: Id::new(1) }; serde_test::assert_tokens( &value, diff --git a/model/src/gateway/payload/incoming/voice_state_update.rs b/model/src/gateway/payload/incoming/voice_state_update.rs index d778db87298..ac28eae270c 100644 --- a/model/src/gateway/payload/incoming/voice_state_update.rs +++ b/model/src/gateway/payload/incoming/voice_state_update.rs @@ -173,10 +173,7 @@ mod tests { nick: Some("Twilight".to_string()), pending: false, premium_since: None, - roles: vec![ - Id::new(123), - Id::new(124), - ], + roles: vec![Id::new(123), Id::new(124)], user: User { id: Id::new(1_234_123_123_123), accent_color: None, diff --git a/model/src/gateway/presence/mod.rs b/model/src/gateway/presence/mod.rs index 63ce84c9c63..142b740391c 100644 --- a/model/src/gateway/presence/mod.rs +++ b/model/src/gateway/presence/mod.rs @@ -212,9 +212,7 @@ mod tests { }, guild_id: Id::new(2), status: Status::Online, - user: UserOrId::UserId { - id: Id::new(1), - }, + user: UserOrId::UserId { id: Id::new(1) }, }; serde_test::assert_de_tokens( @@ -316,9 +314,7 @@ mod tests { }, guild_id: Id::new(2), status: Status::Online, - user: UserOrId::UserId { - id: Id::new(1), - }, + user: UserOrId::UserId { id: Id::new(1) }, }]); let mut json_deserializer = Deserializer::from_str(input); diff --git a/model/src/template/mod.rs b/model/src/template/mod.rs index 9c26814fd41..90cff19d80d 100644 --- a/model/src/template/mod.rs +++ b/model/src/template/mod.rs @@ -225,16 +225,12 @@ mod tests { PermissionOverwrite { allow: Permissions::from_bits(0).unwrap(), deny: Permissions::from_bits(2048).unwrap(), - kind: PermissionOverwriteType::Role( - Id::new(1), - ), + kind: PermissionOverwriteType::Role(Id::new(1)), }, PermissionOverwrite { allow: Permissions::from_bits(2048).unwrap(), deny: Permissions::from_bits(0).unwrap(), - kind: PermissionOverwriteType::Role( - Id::new(2), - ), + kind: PermissionOverwriteType::Role(Id::new(2)), }, ], position: 0, diff --git a/model/src/voice/voice_state.rs b/model/src/voice/voice_state.rs index 05c5f7f9cf2..54c59c81cb9 100644 --- a/model/src/voice/voice_state.rs +++ b/model/src/voice/voice_state.rs @@ -148,8 +148,7 @@ impl<'de> Visitor<'de> for VoiceStateVisitor { return Err(DeError::duplicate_field("member")); } - let deserializer = - OptionalMemberDeserializer::new(Id::new(1)); + let deserializer = OptionalMemberDeserializer::new(Id::new(1)); member = map.next_value_seed(deserializer)?; } diff --git a/util/src/permission_calculator/mod.rs b/util/src/permission_calculator/mod.rs index e82aafe3fdf..5a9ebd7189c 100644 --- a/util/src/permission_calculator/mod.rs +++ b/util/src/permission_calculator/mod.rs @@ -589,10 +589,7 @@ mod tests { let guild_id = Id::new(1); let user_id = Id::new(2); let everyone_role = Permissions::CONNECT; - let roles = &[( - Id::new(3), - Permissions::SEND_MESSAGES, - )]; + let roles = &[(Id::new(3), Permissions::SEND_MESSAGES)]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) .in_channel(ChannelType::GuildVoice, &[]); @@ -605,10 +602,7 @@ mod tests { let guild_id = Id::new(1); let user_id = Id::new(2); let everyone_role = Permissions::CONNECT; - let roles = &[( - Id::new(3), - Permissions::SEND_MESSAGES, - )]; + let roles = &[(Id::new(3), Permissions::SEND_MESSAGES)]; let calculated = PermissionCalculator::new(guild_id, user_id, everyone_role, roles) .in_channel(ChannelType::GuildText, &[]); @@ -645,16 +639,9 @@ mod tests { /// has all denying overwrites ignored. #[test] fn test_admin() { - let member_roles = &[( - Id::new(3), - Permissions::ADMINISTRATOR, - )]; - let calc = PermissionCalculator::new( - Id::new(1), - Id::new(2), - Permissions::empty(), - member_roles, - ); + let member_roles = &[(Id::new(3), Permissions::ADMINISTRATOR)]; + let calc = + PermissionCalculator::new(Id::new(1), Id::new(2), Permissions::empty(), member_roles); assert!(calc.root().is_all()); // Ensure that the denial of "send messages" doesn't actually occur due @@ -681,12 +668,7 @@ mod tests { everyone.remove(Permissions::ADMINISTRATOR); for kind in CHANNEL_TYPES { - let calc = PermissionCalculator::new( - Id::new(1), - Id::new(2), - everyone, - &[], - ); + let calc = PermissionCalculator::new(Id::new(1), Id::new(2), everyone, &[]); let calculated = calc.in_channel(*kind, &[]); assert!(!calculated.intersects(PERMISSIONS_ROOT_ONLY)); From c557eedd28a0e7dfbd62a8788a2aad6b398be8c0 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:51:23 -0500 Subject: [PATCH 09/13] use constants over fns Signed-off-by: Zeyla Hellyer --- cache/in-memory/src/permission.rs | 88 ++++++++----------- .../command/set_command_permissions.rs | 28 +++--- .../interaction/get_followup_message.rs | 18 ++-- .../src/request/guild/create_guild/builder.rs | 8 +- .../guild/member/update_guild_member.rs | 27 +++--- .../interaction/message_component/mod.rs | 14 ++- 6 files changed, 74 insertions(+), 109 deletions(-) diff --git a/cache/in-memory/src/permission.rs b/cache/in-memory/src/permission.rs index 496883823d6..be16b4f2241 100644 --- a/cache/in-memory/src/permission.rs +++ b/cache/in-memory/src/permission.rs @@ -538,40 +538,28 @@ mod tests { assert_impl_all!(RootError: Debug, Send, Sync); /// Guild ID used in tests. - fn guild_id() -> Id { - Id::new(1) - } + const GUILD_ID: Id = Id::new(1); /// ID of the `@everyone` role. - fn everyone_role_id() -> Id { - guild_id().cast() - } + const EVERYONE_ROLE_ID: Id = GUILD_ID.cast(); /// User ID used in tests. - fn user_id() -> Id { - Id::new(2) - } + const USER_ID: Id = Id::new(2); /// ID of another role. - fn other_role_id() -> Id { - Id::new(3) - } + const OTHER_ROLE_ID: Id = Id::new(3); /// ID of the user that owns the guild with the ID [`GUILD_ID`]. - fn owner_id() -> Id { - Id::new(4) - } + const OWNER_ID: Id = Id::new(4); /// ID of the #general channel in the guild. /// /// This has the same ID as the [`GUILD_ID`]. - fn channel_id() -> Id { - guild_id().cast() - } + const CHANNEL_ID: Id = GUILD_ID.cast(); fn base_guild() -> Guild { Guild { - id: guild_id(), + id: GUILD_ID, afk_channel_id: None, afk_timeout: 300, application_id: None, @@ -594,7 +582,7 @@ mod tests { name: "this is a guild".to_owned(), nsfw_level: NSFWLevel::AgeRestricted, owner: Some(false), - owner_id: owner_id(), + owner_id: OWNER_ID, permissions: None, preferred_locale: "en-GB".to_owned(), premium_subscription_count: Some(0), @@ -604,7 +592,7 @@ mod tests { // Give the `@everyone` role a guild level and channel level // permission. role_with_permissions( - everyone_role_id(), + EVERYONE_ROLE_ID, Permissions::CREATE_INVITE | Permissions::VIEW_AUDIT_LOG, ), ]), @@ -629,8 +617,8 @@ mod tests { fn channel() -> Channel { Channel::Guild(GuildChannel::Text(TextChannel { - guild_id: Some(guild_id()), - id: channel_id(), + guild_id: Some(GUILD_ID), + id: CHANNEL_ID, kind: ChannelType::GuildText, last_message_id: None, last_pin_timestamp: None, @@ -641,12 +629,12 @@ mod tests { PermissionOverwrite { allow: Permissions::empty(), deny: Permissions::CREATE_INVITE, - kind: PermissionOverwriteType::Role(everyone_role_id()), + kind: PermissionOverwriteType::Role(EVERYONE_ROLE_ID), }, PermissionOverwrite { allow: Permissions::EMBED_LINKS, deny: Permissions::empty(), - kind: PermissionOverwriteType::Member(user_id()), + kind: PermissionOverwriteType::Member(USER_ID), }, ]), position: 0, @@ -675,17 +663,17 @@ mod tests { let cache = InMemoryCache::new(); let permissions = cache.permissions(); assert!(matches!( - permissions.root(user_id(), guild_id()).unwrap_err().kind(), + permissions.root(USER_ID, GUILD_ID).unwrap_err().kind(), &RootErrorType::MemberUnavailable { guild_id: g_id, user_id: u_id } - if g_id == guild_id() && u_id == user_id() + if g_id == GUILD_ID && u_id == USER_ID )); - cache.update(&MemberAdd(test::member(user_id(), guild_id()))); + cache.update(&MemberAdd(test::member(USER_ID, GUILD_ID))); assert!(matches!( - permissions.root(user_id(), guild_id()).unwrap_err().kind(), + permissions.root(USER_ID, GUILD_ID).unwrap_err().kind(), &RootErrorType::RoleUnavailable { role_id } - if role_id == everyone_role_id() + if role_id == EVERYONE_ROLE_ID )); } @@ -704,23 +692,23 @@ mod tests { let permissions = cache.permissions(); cache.update(&GuildCreate(base_guild())); - cache.update(&MemberAdd(test::member(user_id(), guild_id()))); + cache.update(&MemberAdd(test::member(USER_ID, GUILD_ID))); cache.update(&MemberUpdate { avatar: None, - guild_id: guild_id(), + guild_id: GUILD_ID, deaf: None, joined_at, mute: None, nick: None, pending: false, premium_since: None, - roles: Vec::from([other_role_id()]), - user: test::user(user_id()), + roles: Vec::from([OTHER_ROLE_ID]), + user: test::user(USER_ID), }); cache.update(&role_create( - guild_id(), + GUILD_ID, role_with_permissions( - other_role_id(), + OTHER_ROLE_ID, Permissions::SEND_MESSAGES | Permissions::BAN_MEMBERS, ), )); @@ -730,7 +718,7 @@ mod tests { | Permissions::VIEW_AUDIT_LOG | Permissions::SEND_MESSAGES; - assert_eq!(expected, permissions.root(user_id(), guild_id())?); + assert_eq!(expected, permissions.root(USER_ID, GUILD_ID)?); Ok(()) } @@ -747,41 +735,41 @@ mod tests { cache.update(&GuildCreate(base_guild())); assert!(matches!( - permissions.in_channel(user_id(), channel_id()).unwrap_err().kind(), + permissions.in_channel(USER_ID, CHANNEL_ID).unwrap_err().kind(), ChannelErrorType::ChannelUnavailable { channel_id: c_id } - if *c_id == channel_id() + if *c_id == CHANNEL_ID )); cache.update(&ChannelCreate(channel())); assert!(matches!( - permissions.in_channel(user_id(), channel_id()).unwrap_err().kind(), + permissions.in_channel(USER_ID, CHANNEL_ID).unwrap_err().kind(), ChannelErrorType::MemberUnavailable { guild_id: g_id, user_id: u_id } - if *g_id == guild_id() && *u_id == user_id() + if *g_id == GUILD_ID && *u_id == USER_ID )); cache.update(&MemberAdd({ - let mut member = test::member(user_id(), guild_id()); - member.roles.push(other_role_id()); + let mut member = test::member(USER_ID, GUILD_ID); + member.roles.push(OTHER_ROLE_ID); member })); assert!(matches!( - permissions.in_channel(user_id(), channel_id()).unwrap_err().kind(), + permissions.in_channel(USER_ID, CHANNEL_ID).unwrap_err().kind(), &ChannelErrorType::RoleUnavailable { role_id } - if role_id == other_role_id() + if role_id == OTHER_ROLE_ID )); cache.update(&role_create( - guild_id(), + GUILD_ID, role_with_permissions( - other_role_id(), + OTHER_ROLE_ID, Permissions::SEND_MESSAGES | Permissions::BAN_MEMBERS, ), )); assert_eq!( Permissions::EMBED_LINKS | Permissions::SEND_MESSAGES, - permissions.in_channel(user_id(), channel_id())?, + permissions.in_channel(USER_ID, CHANNEL_ID)?, ); Ok(()) @@ -801,10 +789,10 @@ mod tests { let permissions = cache.permissions(); cache.update(&GuildCreate(base_guild())); - assert!(permissions.root(owner_id(), guild_id())?.is_all()); + assert!(permissions.root(OWNER_ID, GUILD_ID)?.is_all()); cache.update(&ChannelCreate(channel())); - assert!(permissions.in_channel(owner_id(), channel_id())?.is_all()); + assert!(permissions.in_channel(OWNER_ID, CHANNEL_ID)?.is_all()); Ok(()) } diff --git a/http/src/request/application/command/set_command_permissions.rs b/http/src/request/application/command/set_command_permissions.rs index f5cef6bd0f9..cbf1c891fdf 100644 --- a/http/src/request/application/command/set_command_permissions.rs +++ b/http/src/request/application/command/set_command_permissions.rs @@ -230,13 +230,8 @@ mod tests { CommandValidationErrorType, GUILD_COMMAND_LIMIT, GUILD_COMMAND_PERMISSION_LIMIT, }; - const fn application_id() -> Id { - Id::new(1) - } - - const fn guild_id() -> Id { - Id::new(2) - } + const GUILD_ID: Id = Id::new(2); + const APPLICATION_ID: Id = Id::new(1); #[derive(Debug, Deserialize, Eq, PartialEq)] struct GuildCommandPermissionDeserializable { @@ -285,7 +280,7 @@ mod tests { ]; let builder = - SetCommandPermissions::new(&http, application_id(), guild_id(), command_permissions)?; + SetCommandPermissions::new(&http, APPLICATION_ID, GUILD_ID, command_permissions)?; let request = builder.try_into_request()?; let body = request.body().expect("body must be present"); @@ -327,7 +322,7 @@ mod tests { .collect::>(); let request = - SetCommandPermissions::new(&http, application_id(), guild_id(), &command_permissions); + SetCommandPermissions::new(&http, APPLICATION_ID, GUILD_ID, &command_permissions); assert!(matches!( request.unwrap_err().kind(), CommandValidationErrorType::PermissionsCountInvalid @@ -345,13 +340,10 @@ mod tests { }) .collect::>(); - assert!(SetCommandPermissions::new( - &http, - application_id(), - guild_id(), - &command_permissions - ) - .is_ok()); + assert!( + SetCommandPermissions::new(&http, APPLICATION_ID, GUILD_ID, &command_permissions) + .is_ok() + ); } #[test] @@ -364,7 +356,7 @@ mod tests { .collect::>(); let request = - SetCommandPermissions::new(&http, application_id(), guild_id(), &command_permissions); + SetCommandPermissions::new(&http, APPLICATION_ID, GUILD_ID, &command_permissions); assert!(matches!( request.unwrap_err().kind(), CommandValidationErrorType::CountInvalid @@ -375,6 +367,6 @@ mod tests { fn test_no_permissions() { let http = Client::new("token".to_owned()); - assert!(SetCommandPermissions::new(&http, application_id(), guild_id(), &[]).is_ok()); + assert!(SetCommandPermissions::new(&http, APPLICATION_ID, GUILD_ID, &[]).is_ok()); } } diff --git a/http/src/request/application/interaction/get_followup_message.rs b/http/src/request/application/interaction/get_followup_message.rs index d545252af8b..ebbc2c8932a 100644 --- a/http/src/request/application/interaction/get_followup_message.rs +++ b/http/src/request/application/interaction/get_followup_message.rs @@ -103,27 +103,21 @@ mod tests { #[test] fn test_request() -> Result<(), Box> { + const APPLICATION_ID: Id = Id::new(1); + const MESSAGE_ID: Id = Id::new(2); const TOKEN: &str = "token"; - const fn application_id() -> Id { - Id::new(1) - } - - const fn message_id() -> Id { - Id::new(2) - } - let client = Client::new("token".to_owned()); let actual = client - .interaction(application_id()) - .followup_message(TOKEN, message_id()) + .interaction(APPLICATION_ID) + .followup_message(TOKEN, MESSAGE_ID) .try_into_request()?; let expected = Request::builder(&Route::GetFollowupMessage { - application_id: application_id().get(), + application_id: APPLICATION_ID.get(), interaction_token: TOKEN, thread_id: None, - message_id: message_id().get(), + message_id: MESSAGE_ID.get(), }) .use_authorization_token(false) .build(); diff --git a/http/src/request/guild/create_guild/builder.rs b/http/src/request/guild/create_guild/builder.rs index 2e7d0ef2da3..e071244fbdd 100644 --- a/http/src/request/guild/create_guild/builder.rs +++ b/http/src/request/guild/create_guild/builder.rs @@ -83,16 +83,14 @@ impl RoleFieldsBuilder { /// [`color`]: Self::color pub const COLOR_MAXIMUM: u32 = 0xff_ff_ff; - const fn role_id() -> Id { - Id::new(1) - } + const ROLE_ID: Id = Id::new(1); /// Create a new default role field builder. pub const fn new(name: String) -> Self { Self(RoleFields { color: None, hoist: None, - id: Self::role_id(), + id: Self::ROLE_ID, mentionable: None, name, permissions: None, @@ -140,7 +138,7 @@ impl RoleFieldsBuilder { /// Returns a [`RoleFieldsErrorType::IdInvalid`] error type if the ID is set /// to 1. pub fn id(mut self, id: Id) -> Result { - if id == Self::role_id() { + if id == Self::ROLE_ID { return Err(RoleFieldsError { kind: RoleFieldsErrorType::IdInvalid, }); diff --git a/http/src/request/guild/member/update_guild_member.rs b/http/src/request/guild/member/update_guild_member.rs index 00c8f4fec0c..b1813588a07 100644 --- a/http/src/request/guild/member/update_guild_member.rs +++ b/http/src/request/guild/member/update_guild_member.rs @@ -203,18 +203,13 @@ mod tests { Id, }; - const fn guild_id() -> Id { - Id::new(1) - } - - const fn user_id() -> Id { - Id::new(1) - } + const GUILD_ID: Id = Id::new(1); + const USER_ID: Id = Id::new(1); #[test] fn test_request() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let builder = UpdateGuildMember::new(&client, guild_id(), user_id()) + let builder = UpdateGuildMember::new(&client, GUILD_ID, USER_ID) .deaf(true) .mute(true); let actual = builder.try_into_request()?; @@ -228,8 +223,8 @@ mod tests { roles: None, }; let route = Route::UpdateMember { - guild_id: guild_id().get(), - user_id: user_id().get(), + guild_id: GUILD_ID.get(), + user_id: USER_ID.get(), }; let expected = Request::builder(&route).json(&body)?.build(); @@ -242,7 +237,7 @@ mod tests { #[test] fn test_nick_set_null() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let builder = UpdateGuildMember::new(&client, guild_id(), user_id()).nick(None)?; + let builder = UpdateGuildMember::new(&client, GUILD_ID, USER_ID).nick(None)?; let actual = builder.try_into_request()?; let body = UpdateGuildMemberFields { @@ -254,8 +249,8 @@ mod tests { roles: None, }; let route = Route::UpdateMember { - guild_id: guild_id().get(), - user_id: user_id().get(), + guild_id: GUILD_ID.get(), + user_id: USER_ID.get(), }; let expected = Request::builder(&route).json(&body)?.build(); @@ -267,7 +262,7 @@ mod tests { #[test] fn test_nick_set_value() -> Result<(), Box> { let client = Client::new("foo".to_owned()); - let builder = UpdateGuildMember::new(&client, guild_id(), user_id()).nick(Some("foo"))?; + let builder = UpdateGuildMember::new(&client, GUILD_ID, USER_ID).nick(Some("foo"))?; let actual = builder.try_into_request()?; let body = UpdateGuildMemberFields { @@ -279,8 +274,8 @@ mod tests { roles: None, }; let route = Route::UpdateMember { - guild_id: guild_id().get(), - user_id: user_id().get(), + guild_id: GUILD_ID.get(), + user_id: USER_ID.get(), }; let expected = Request::builder(&route).json(&body)?.build(); diff --git a/model/src/application/interaction/message_component/mod.rs b/model/src/application/interaction/message_component/mod.rs index 59a9bb72623..355153fb3aa 100644 --- a/model/src/application/interaction/message_component/mod.rs +++ b/model/src/application/interaction/message_component/mod.rs @@ -136,9 +136,7 @@ mod tests { #[test] fn test_author_id() -> Result<(), TimestampParseError> { - const fn user_id() -> Id { - Id::new(7) - } + const USER_ID: Id = Id::new(7); let timestamp = Timestamp::from_str("2020-02-02T02:02:02.020000+00:00")?; @@ -163,14 +161,14 @@ mod tests { permissions: None, premium_since: None, roles: Vec::new(), - user: Some(user(user_id())), + user: Some(user(USER_ID)), }), message: Message { activity: None, application: None, application_id: None, attachments: Vec::new(), - author: user(user_id()), + author: user(USER_ID), channel_id: Id::new(5), components: Vec::new(), content: String::new(), @@ -200,7 +198,7 @@ mod tests { user: None, }; - assert_eq!(Some(user_id()), in_guild.author_id()); + assert_eq!(Some(USER_ID), in_guild.author_id()); let in_dm = MessageComponentInteraction { member: None, @@ -208,10 +206,10 @@ mod tests { guild_id: None, ..in_guild.message }, - user: Some(user(user_id())), + user: Some(user(USER_ID)), ..in_guild }; - assert_eq!(Some(user_id()), in_dm.author_id()); + assert_eq!(Some(USER_ID), in_dm.author_id()); Ok(()) } From b505933841917dd551bbb6843de857820aa60980 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 15:56:22 -0500 Subject: [PATCH 10/13] clippy Signed-off-by: Zeyla Hellyer --- util/src/builder/command.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/src/builder/command.rs b/util/src/builder/command.rs index b25791a5ab8..89181158726 100644 --- a/util/src/builder/command.rs +++ b/util/src/builder/command.rs @@ -45,7 +45,7 @@ pub struct CommandBuilder(Command); impl CommandBuilder { /// Create a new default [`Command`] builder. #[must_use = "builders have no effect if unused"] - pub fn new(name: String, description: String, kind: CommandType) -> Self { + pub const fn new(name: String, description: String, kind: CommandType) -> Self { Self(Command { application_id: None, default_permission: None, From 0078f153b05bf8c83da18e529177a967e05a9c27 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 17:36:42 -0500 Subject: [PATCH 11/13] Update model/src/id/mod.rs Co-authored-by: Vilgot Fredenberg --- model/src/id/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/src/id/mod.rs b/model/src/id/mod.rs index 98b0715c306..564366f7152 100644 --- a/model/src/id/mod.rs +++ b/model/src/id/mod.rs @@ -113,7 +113,7 @@ impl Id { if let Some(id) = Self::new_checked(n) { id } else { - panic!("value passed to `Id::new` is zero"); + panic!("value is zero"); } } From 64578df0ac02937fad5a4599f6dadab8cc79e1cc Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Thu, 30 Dec 2021 17:37:00 -0500 Subject: [PATCH 12/13] Update examples/lavalink-basic-bot/src/main.rs Co-authored-by: Vilgot Fredenberg --- examples/lavalink-basic-bot/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lavalink-basic-bot/src/main.rs b/examples/lavalink-basic-bot/src/main.rs index c6b463f0a0c..8c3590d541d 100644 --- a/examples/lavalink-basic-bot/src/main.rs +++ b/examples/lavalink-basic-bot/src/main.rs @@ -113,7 +113,7 @@ async fn join(msg: Message, state: State) -> Result<(), Box()?); + let channel_id = msg.content.parse()?; let guild_id = msg.guild_id.expect("known to be present"); state From 01bcd7ecf9b6bd4d8f51571947b5e18abb8251cc Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Fri, 31 Dec 2021 00:56:07 -0500 Subject: [PATCH 13/13] unused import Signed-off-by: Zeyla Hellyer --- examples/lavalink-basic-bot/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/lavalink-basic-bot/src/main.rs b/examples/lavalink-basic-bot/src/main.rs index 8c3590d541d..4431ab1f917 100644 --- a/examples/lavalink-basic-bot/src/main.rs +++ b/examples/lavalink-basic-bot/src/main.rs @@ -14,7 +14,6 @@ use twilight_lavalink::{ use twilight_model::{ channel::Message, gateway::payload::{incoming::MessageCreate, outgoing::UpdateVoiceState}, - id::Id, }; use twilight_standby::Standby;