From 1fdeeaee6cdb99720536f7b6a19f4aa0ccd0eac6 Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Wed, 18 Jan 2023 12:35:07 -0500 Subject: [PATCH] refactor: denylist macros Add a Clippy denylist for macros. Denies the use of the following macros: - `serde_json::json` - `std::vec` - `std::write` Closes #1628. --- clippy.toml | 5 + examples/gateway-request-members.rs | 2 +- examples/model-webhook-slash.rs | 4 +- twilight-cache-inmemory/src/event/emoji.rs | 8 +- twilight-cache-inmemory/src/event/guild.rs | 2 +- .../src/event/interaction.rs | 6 +- twilight-cache-inmemory/src/lib.rs | 6 +- twilight-cache-inmemory/src/model/emoji.rs | 4 +- twilight-gateway/src/shard/builder.rs | 4 +- .../src/shard/processor/compression/mod.rs | 2 +- .../tests/test_shard_command_ratelimit.rs | 4 +- .../src/request/guild/create_guild/builder.rs | 36 +- .../src/request/guild/create_guild/mod.rs | 8 +- twilight-lavalink/src/http.rs | 11 +- twilight-lavalink/src/node.rs | 19 +- .../application_command/resolved.rs | 4 +- .../message/allowed_mentions/builder.rs | 16 +- .../channel/message/allowed_mentions/mod.rs | 6 +- .../src/channel/message/component/mod.rs | 4 +- .../src/channel/message/embed/mod.rs | 4 +- twilight-model/src/channel/message/mod.rs | 16 +- twilight-model/src/channel/mod.rs | 550 +++++++++++++----- twilight-model/src/gateway/event/shard.rs | 8 +- .../gateway/payload/incoming/member_add.rs | 2 +- .../gateway/payload/incoming/member_chunk.rs | 466 +++++++++++---- .../gateway/payload/incoming/member_update.rs | 2 +- .../src/gateway/payload/incoming/ready.rs | 4 +- .../payload/incoming/thread_members_update.rs | 8 +- .../gateway/payload/incoming/typing_start.rs | 2 +- .../payload/incoming/voice_state_update.rs | 4 +- .../payload/outgoing/request_guild_members.rs | 2 +- twilight-model/src/gateway/presence/mod.rs | 4 +- twilight-model/src/gateway/reaction.rs | 2 +- twilight-model/src/guild/emoji.rs | 2 +- twilight-model/src/guild/invite/guild.rs | 6 +- twilight-model/src/guild/invite/mod.rs | 6 +- .../src/guild/invite/welcome_screen.rs | 4 +- twilight-model/src/guild/partial_member.rs | 2 +- twilight-model/src/guild/preview.rs | 6 +- twilight-model/src/guild/template/mod.rs | 14 +- twilight-model/src/oauth/application.rs | 2 +- twilight-model/src/oauth/team/member.rs | 2 +- twilight-model/src/user/current_user.rs | 8 +- twilight-model/src/user/current_user_guild.rs | 2 +- twilight-model/src/user/mod.rs | 8 +- twilight-model/src/user/profile.rs | 4 +- .../src/builder/interaction_response_data.rs | 6 +- 47 files changed, 890 insertions(+), 407 deletions(-) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 00000000000..95d2495d1a3 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,5 @@ +disallowed-macros = [ + { path = "serde_json::json", reason = "less flexible and performant, use structs and serde_derive"}, + { path = "std::vec", reason = "the Vec::new and Vec::from methods are preferred" }, + { path = "std::write", reason = "slow to compile and run, use Formatter, Display, or Debug calls instead"}, +] diff --git a/examples/gateway-request-members.rs b/examples/gateway-request-members.rs index 866a13a7612..6d5ae7ea110 100644 --- a/examples/gateway-request-members.rs +++ b/examples/gateway-request-members.rs @@ -41,7 +41,7 @@ async fn main() -> anyhow::Result<()> { // 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::from([Id::new(2), Id::new(3)])) .unwrap(); shard.command(&request).await?; diff --git a/examples/model-webhook-slash.rs b/examples/model-webhook-slash.rs index 5f0fa9b144c..3fb2f959ec8 100644 --- a/examples/model-webhook-slash.rs +++ b/examples/model-webhook-slash.rs @@ -78,7 +78,9 @@ where // Check if the signature matches and else return a error response. if PUB_KEY .verify( - vec![timestamp.as_bytes(), &whole_body].concat().as_ref(), + Vec::from([timestamp.as_bytes(), &whole_body]) + .concat() + .as_ref(), &signature, ) .is_err() diff --git a/twilight-cache-inmemory/src/event/emoji.rs b/twilight-cache-inmemory/src/event/emoji.rs index be8ae82df9e..f48833c914f 100644 --- a/twilight-cache-inmemory/src/event/emoji.rs +++ b/twilight-cache-inmemory/src/event/emoji.rs @@ -160,7 +160,7 @@ mod tests { cache.cache_emoji(guild_id, emote_3.clone()); cache.update(&GuildEmojisUpdate { - emojis: vec![emote.clone(), emote_3.clone()], + emojis: Vec::from([emote.clone(), emote_3.clone()]), guild_id, }); @@ -171,7 +171,7 @@ mod tests { assert!(cache.emoji(emote_3.id).is_some()); cache.update(&GuildEmojisUpdate { - emojis: vec![emote.clone()], + emojis: Vec::from([emote.clone()]), guild_id, }); @@ -183,7 +183,7 @@ mod tests { let emote_4 = test::emoji(Id::new(4), None); cache.update(&GuildEmojisUpdate { - emojis: vec![emote_4.clone()], + emojis: Vec::from([emote_4.clone()]), guild_id, }); @@ -193,7 +193,7 @@ mod tests { assert!(cache.emoji(emote.id).is_none()); cache.update(&GuildEmojisUpdate { - emojis: vec![], + emojis: Vec::new(), guild_id, }); diff --git a/twilight-cache-inmemory/src/event/guild.rs b/twilight-cache-inmemory/src/event/guild.rs index c03d3acf673..7e533e77f5b 100644 --- a/twilight-cache-inmemory/src/event/guild.rs +++ b/twilight-cache-inmemory/src/event/guild.rs @@ -403,7 +403,7 @@ mod tests { discovery_splash: None, emojis: Vec::new(), explicit_content_filter: ExplicitContentFilter::AllMembers, - features: vec![], + features: Vec::new(), icon: None, id: Id::new(123), joined_at: Some(Timestamp::from_secs(1_632_072_645).expect("non zero")), diff --git a/twilight-cache-inmemory/src/event/interaction.rs b/twilight-cache-inmemory/src/event/interaction.rs index edb24664342..5af28665996 100644 --- a/twilight-cache-inmemory/src/event/interaction.rs +++ b/twilight-cache-inmemory/src/event/interaction.rs @@ -120,7 +120,7 @@ mod tests { pending: false, permissions: Permissions::empty(), premium_since: None, - roles: vec![Id::new(8)], + roles: Vec::from([Id::new(8)]), }, )]), messages: HashMap::from([( @@ -176,11 +176,11 @@ mod tests { pinned: false, reactions: Vec::new(), reference: None, - sticker_items: vec![MessageSticker { + sticker_items: Vec::from([MessageSticker { format_type: StickerFormatType::Png, id: Id::new(1), name: "sticker name".to_owned(), - }], + }]), referenced_message: None, thread: None, timestamp, diff --git a/twilight-cache-inmemory/src/lib.rs b/twilight-cache-inmemory/src/lib.rs index a39facc96e3..aed59ac249e 100644 --- a/twilight-cache-inmemory/src/lib.rs +++ b/twilight-cache-inmemory/src/lib.rs @@ -965,14 +965,14 @@ mod tests { nick: None, pending: false, premium_since: None, - roles: vec![Id::new(1), Id::new(2)], + roles: Vec::from([Id::new(1), Id::new(2)]), user, }, ); cache.cache_roles( guild_id, - vec![ + Vec::from([ Role { color: 0, hoist: false, @@ -999,7 +999,7 @@ mod tests { tags: None, unicode_emoji: None, }, - ], + ]), ); assert_eq!( diff --git a/twilight-cache-inmemory/src/model/emoji.rs b/twilight-cache-inmemory/src/model/emoji.rs index 5b2b905e2ed..c24be0da8b5 100644 --- a/twilight-cache-inmemory/src/model/emoji.rs +++ b/twilight-cache-inmemory/src/model/emoji.rs @@ -141,7 +141,7 @@ mod tests { name: "foo".to_owned(), managed: false, require_colons: true, - roles: vec![], + roles: Vec::new(), user: None, available: true, }; @@ -151,7 +151,7 @@ mod tests { name: "foo".to_owned(), managed: false, require_colons: true, - roles: vec![], + roles: Vec::new(), user_id: None, available: true, }; diff --git a/twilight-gateway/src/shard/builder.rs b/twilight-gateway/src/shard/builder.rs index 1b60e1f17d5..63dc65e9d49 100644 --- a/twilight-gateway/src/shard/builder.rs +++ b/twilight-gateway/src/shard/builder.rs @@ -265,12 +265,12 @@ impl ShardBuilder { /// # fn main() -> Result<(), Box> { /// let shard = Shard::builder(env::var("DISCORD_TOKEN")?, Intents::empty()).presence( /// UpdatePresencePayload::new( - /// vec![MinimalActivity { + /// Vec::from([MinimalActivity { /// kind: ActivityType::Playing, /// name: "Not accepting commands".into(), /// url: None, /// } - /// .into()], + /// .into()]), /// false, /// None, /// Status::Idle, diff --git a/twilight-gateway/src/shard/processor/compression/mod.rs b/twilight-gateway/src/shard/processor/compression/mod.rs index 10d7cf41010..bd1025b8c29 100644 --- a/twilight-gateway/src/shard/processor/compression/mod.rs +++ b/twilight-gateway/src/shard/processor/compression/mod.rs @@ -119,7 +119,7 @@ impl Compression { /// message failed. #[cfg_attr( not(any(feature = "zlib-stock", feature = "zlib-simd")), - allow(clippy::unused_self) + allow(clippy::unnecessary_wraps, clippy::unused_self) )] pub fn message_mut(&mut self) -> Result, ReceivingEventError> { #[cfg(any(feature = "zlib-stock", feature = "zlib-simd"))] diff --git a/twilight-gateway/tests/test_shard_command_ratelimit.rs b/twilight-gateway/tests/test_shard_command_ratelimit.rs index 16738c1246d..87c6143aeec 100644 --- a/twilight-gateway/tests/test_shard_command_ratelimit.rs +++ b/twilight-gateway/tests/test_shard_command_ratelimit.rs @@ -44,7 +44,7 @@ async fn test_shard_command_ratelimit() { // now that we're connected we can test sending let payload = UpdatePresence::new( - vec![Activity { + Vec::from([Activity { application_id: None, assets: None, buttons: Vec::new(), @@ -61,7 +61,7 @@ async fn test_shard_command_ratelimit() { state: None, timestamps: None, url: None, - }], + }]), false, Some(1), Status::DoNotDisturb, diff --git a/twilight-http/src/request/guild/create_guild/builder.rs b/twilight-http/src/request/guild/create_guild/builder.rs index 41fb3469df2..2f8969b7730 100644 --- a/twilight-http/src/request/guild/create_guild/builder.rs +++ b/twilight-http/src/request/guild/create_guild/builder.rs @@ -784,7 +784,7 @@ mod tests { VoiceFieldsBuilder::new("voicename".to_owned()) .unwrap() .bitrate(96_000) - .permission_overwrites(vec![overwrite()]) + .permission_overwrites(Vec::from([overwrite()])) .user_limit(40) .build() } @@ -838,12 +838,12 @@ mod tests { id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some(perms()), deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role, - }]), + }])), parent_id: None, user_limit: Some(40), } @@ -854,7 +854,7 @@ mod tests { TextFieldsBuilder::new("textname".to_owned()) .unwrap() .nsfw() - .permission_overwrites(vec![overwrite()]) + .permission_overwrites(Vec::from([overwrite()])) .rate_limit_per_user(4_000) .unwrap() .topic("a topic".to_owned()) @@ -877,12 +877,12 @@ mod tests { kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some(perms()), deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role - }]), + }])), parent_id: None, rate_limit_per_user: Some(4_000), topic: Some(String::from("a topic")), @@ -910,7 +910,7 @@ mod tests { assert_eq!( channels.build(), - vec![ + Vec::from([ GuildChannelFields::Category(CategoryFields { id: Id::new(2), kind: ChannelType::GuildCategory, @@ -922,7 +922,7 @@ mod tests { kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some( Permissions::CONNECT | Permissions::SPEAK @@ -931,7 +931,7 @@ mod tests { deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role, - }]), + }])), parent_id: Some(Id::new(2)), rate_limit_per_user: Some(4_000), topic: Some(String::from("a topic")), @@ -941,7 +941,7 @@ mod tests { id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some( Permissions::CONNECT | Permissions::SPEAK @@ -950,11 +950,11 @@ mod tests { deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role, - }]), + }])), parent_id: Some(Id::new(2)), user_limit: Some(40), }), - ] + ]) ); } @@ -966,13 +966,13 @@ mod tests { assert_eq!( channels.build(), - vec![ + Vec::from([ GuildChannelFields::Text(TextFields { id: Id::new(1), kind: ChannelType::GuildText, name: String::from("textname"), nsfw: Some(true), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some( Permissions::CONNECT | Permissions::SPEAK @@ -981,7 +981,7 @@ mod tests { deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role, - }]), + }])), parent_id: None, rate_limit_per_user: Some(4_000), topic: Some(String::from("a topic")), @@ -991,7 +991,7 @@ mod tests { id: Id::new(1), kind: ChannelType::GuildVoice, name: String::from("voicename"), - permission_overwrites: Some(vec![PermissionOverwrite { + permission_overwrites: Some(Vec::from([PermissionOverwrite { allow: Some( Permissions::CONNECT | Permissions::SPEAK @@ -1000,11 +1000,11 @@ mod tests { deny: Some(Permissions::empty()), id: Id::new(2), kind: PermissionOverwriteType::Role, - }]), + }])), parent_id: None, user_limit: Some(40), }), - ] + ]) ); } } diff --git a/twilight-http/src/request/guild/create_guild/mod.rs b/twilight-http/src/request/guild/create_guild/mod.rs index 4f55e61f1fe..af6ba4a23df 100644 --- a/twilight-http/src/request/guild/create_guild/mod.rs +++ b/twilight-http/src/request/guild/create_guild/mod.rs @@ -256,7 +256,7 @@ impl<'a> CreateGuild<'a> { pub fn add_role(mut self, role: RoleFields) -> Self { if self.fields.roles.is_none() { let builder = RoleFieldsBuilder::new("@everyone".to_owned()); - self.fields.roles.replace(vec![builder.build()]); + self.fields.roles.replace(Vec::from([builder.build()])); } if let Some(roles) = self.fields.roles.as_mut() { @@ -389,7 +389,7 @@ impl<'a> CreateGuild<'a> { roles.remove(0); roles.insert(0, everyone); } else { - self.fields.roles.replace(vec![everyone]); + self.fields.roles.replace(Vec::from([everyone])); } self @@ -424,9 +424,9 @@ impl<'a> CreateGuild<'a> { /// # #[tokio::main] async fn main() -> Result<(), Box> { /// # let client = Client::new("my token".to_owned()); /// - /// let roles = vec![RoleFieldsBuilder::new("role 1".to_owned()) + /// let roles = Vec::from([RoleFieldsBuilder::new("role 1".to_owned()) /// .color(0x543923)? - /// .build()]; + /// .build()]); /// client /// .create_guild("guild name".to_owned())? /// .roles(roles)? diff --git a/twilight-lavalink/src/http.rs b/twilight-lavalink/src/http.rs index 9b9ab847e52..ccded20e325 100644 --- a/twilight-lavalink/src/http.rs +++ b/twilight-lavalink/src/http.rs @@ -300,15 +300,20 @@ pub fn unmark_failed_address( authorization: impl AsRef, route_address: impl Into, ) -> Result>, HttpError> { + #[derive(Serialize)] + struct UnmarkFailedRequestBody { + address: IpAddr, + } + let mut req = Request::post(format!("{}/routeplanner/status", node_address.into())); let auth_value = HeaderValue::from_str(authorization.as_ref())?; req = req.header(AUTHORIZATION, auth_value); req.body( - serde_json::to_vec(&serde_json::json!({ - "address": route_address.into(), - })) + serde_json::to_vec(&UnmarkFailedRequestBody { + address: route_address.into(), + }) .expect("valid json"), ) } diff --git a/twilight-lavalink/src/node.rs b/twilight-lavalink/src/node.rs index 46e0dbe047f..f692a7e9957 100644 --- a/twilight-lavalink/src/node.rs +++ b/twilight-lavalink/src/node.rs @@ -27,6 +27,7 @@ use futures_util::{ stream::{Stream, StreamExt}, }; use http::{header::HeaderName, Request, Response, StatusCode}; +use serde::Serialize; use std::{ error::Error, fmt::{Display, Formatter, Result as FmtResult}, @@ -625,6 +626,12 @@ fn connect_request(state: &NodeConfig) -> Result, NodeError> { async fn reconnect( config: &NodeConfig, ) -> Result>, NodeError> { + #[derive(Serialize)] + struct ReconnectBody { + key: SocketAddr, + op: &'static str, + timeout: u64, + } let (mut stream, res) = backoff(config).await?; let headers = res.headers(); @@ -636,12 +643,12 @@ async fn reconnect( if value.as_bytes() == b"false" { tracing::debug!("session to node {} didn't resume", config.address); - let payload = serde_json::json!({ - "op": "configureResuming", - "key": config.address, - "timeout": resume.timeout, - }); - let msg = Message::Text(serde_json::to_string(&payload).unwrap()); + let body = ReconnectBody { + key: config.address, + op: "configureResuming", + timeout: resume.timeout, + }; + let msg = Message::Text(serde_json::to_string(&body).unwrap()); stream.send(msg).await.unwrap(); } else { diff --git a/twilight-model/src/application/interaction/application_command/resolved.rs b/twilight-model/src/application/interaction/application_command/resolved.rs index 06697a36f6e..6db80404a96 100644 --- a/twilight-model/src/application/interaction/application_command/resolved.rs +++ b/twilight-model/src/application/interaction/application_command/resolved.rs @@ -213,11 +213,11 @@ mod tests { pinned: false, reactions: Vec::new(), reference: None, - sticker_items: vec![MessageSticker { + sticker_items: Vec::from([MessageSticker { format_type: StickerFormatType::Png, id: Id::new(1), name: "sticker name".to_owned(), - }], + }]), referenced_message: None, thread: None, timestamp, diff --git a/twilight-model/src/channel/message/allowed_mentions/builder.rs b/twilight-model/src/channel/message/allowed_mentions/builder.rs index a559b603442..52befc319a2 100644 --- a/twilight-model/src/channel/message/allowed_mentions/builder.rs +++ b/twilight-model/src/channel/message/allowed_mentions/builder.rs @@ -125,9 +125,9 @@ mod tests { assert_eq!( value, AllowedMentions { - parse: vec![ParseTypes::Everyone, ParseTypes::Users, ParseTypes::Roles], - users: vec![], - roles: vec![], + parse: Vec::from([ParseTypes::Everyone, ParseTypes::Users, ParseTypes::Roles]), + users: Vec::new(), + roles: Vec::new(), replied_user: true }, ); @@ -137,17 +137,17 @@ mod tests { fn validation() { let value = AllowedMentionsBuilder::new() .users() - .user_ids(vec![Id::new(100), Id::new(200)]) + .user_ids(Vec::from([Id::new(100), Id::new(200)])) .roles() - .role_ids(vec![Id::new(300)]) + .role_ids(Vec::from([Id::new(300)])) .build(); assert_eq!( value, AllowedMentions { - parse: vec![], - users: vec![Id::new(100), Id::new(200)], - roles: vec![Id::new(300)], + parse: Vec::new(), + users: Vec::from([Id::new(100), Id::new(200)]), + roles: Vec::from([Id::new(300)]), replied_user: false, }, ); diff --git a/twilight-model/src/channel/message/allowed_mentions/mod.rs b/twilight-model/src/channel/message/allowed_mentions/mod.rs index 9bab7979b6b..8c72e7a1145 100644 --- a/twilight-model/src/channel/message/allowed_mentions/mod.rs +++ b/twilight-model/src/channel/message/allowed_mentions/mod.rs @@ -88,9 +88,9 @@ mod tests { #[test] fn full() { let value = AllowedMentions { - parse: vec![ParseTypes::Everyone], - users: vec![Id::new(100)], - roles: vec![Id::new(200)], + parse: Vec::from([ParseTypes::Everyone]), + users: Vec::from([Id::new(100)]), + roles: Vec::from([Id::new(200)]), replied_user: true, }; diff --git a/twilight-model/src/channel/message/component/mod.rs b/twilight-model/src/channel/message/component/mod.rs index c97b6455347..e452ae7f2bf 100644 --- a/twilight-model/src/channel/message/component/mod.rs +++ b/twilight-model/src/channel/message/component/mod.rs @@ -63,7 +63,7 @@ use std::fmt::{Formatter, Result as FmtResult}; /// }; /// /// Component::ActionRow(ActionRow { -/// components: vec![Component::SelectMenu(SelectMenu { +/// components: Vec::from([Component::SelectMenu(SelectMenu { /// custom_id: "class_select_1".to_owned(), /// disabled: false, /// max_values: Some(3), @@ -104,7 +104,7 @@ use std::fmt::{Formatter, Result as FmtResult}; /// }, /// ]), /// placeholder: Some("Choose a class".to_owned()), -/// })], +/// })]), /// }); /// ``` #[derive(Clone, Debug, Eq, Hash, PartialEq)] diff --git a/twilight-model/src/channel/message/embed/mod.rs b/twilight-model/src/channel/message/embed/mod.rs index 6b83eaf39ee..01696f26502 100644 --- a/twilight-model/src/channel/message/embed/mod.rs +++ b/twilight-model/src/channel/message/embed/mod.rs @@ -122,11 +122,11 @@ mod tests { }), color: Some(123), description: Some("a description".to_owned()), - fields: vec![EmbedField { + fields: Vec::from([EmbedField { inline: true, name: "name".to_owned(), value: "value".to_owned(), - }], + }]), footer: Some(EmbedFooter { icon_url: Some("https://example.com/1.png".to_owned()), proxy_icon_url: Some("https://cdn.example.com/1-hash.png".to_owned()), diff --git a/twilight-model/src/channel/message/mod.rs b/twilight-model/src/channel/message/mod.rs index 1c77a19774b..09e6bdba61b 100644 --- a/twilight-model/src/channel/message/mod.rs +++ b/twilight-model/src/channel/message/mod.rs @@ -258,11 +258,11 @@ mod tests { pinned: false, reactions: Vec::new(), reference: None, - sticker_items: vec![MessageSticker { + sticker_items: Vec::from([MessageSticker { format_type: StickerFormatType::Png, id: Id::new(1), name: "sticker name".to_owned(), - }], + }]), referenced_message: None, timestamp, thread: None, @@ -441,34 +441,34 @@ mod tests { roles: Vec::new(), user: None, }), - mention_channels: vec![ChannelMention { + mention_channels: Vec::from([ChannelMention { guild_id: Id::new(1), id: Id::new(2), kind: ChannelType::GuildText, name: "channel".to_owned(), - }], + }]), mention_everyone: false, mention_roles: Vec::new(), mentions: Vec::new(), pinned: false, - reactions: vec![Reaction { + reactions: Vec::from([Reaction { count: 7, emoji: ReactionType::Unicode { name: "a".to_owned(), }, me: true, - }], + }]), reference: Some(MessageReference { channel_id: Some(Id::new(1)), guild_id: None, message_id: None, fail_if_not_exists: None, }), - sticker_items: vec![MessageSticker { + sticker_items: Vec::from([MessageSticker { format_type: StickerFormatType::Png, id: Id::new(1), name: "sticker name".to_owned(), - }], + }]), referenced_message: None, timestamp, thread: None, diff --git a/twilight-model/src/channel/mod.rs b/twilight-model/src/channel/mod.rs index 8cb0d09abbb..03612db4262 100644 --- a/twilight-model/src/channel/mod.rs +++ b/twilight-model/src/channel/mod.rs @@ -186,38 +186,13 @@ mod tests { id::Id, util::Timestamp, }; + use serde_test::Token; // The deserializer for GuildChannel should skip over fields names that // it couldn't deserialize. + #[allow(clippy::too_many_lines)] #[test] fn guild_channel_unknown_field_deserialization() { - let input = serde_json::json!({ - "type": 0, - "topic": "a", - "rate_limit_per_user": 0, - "position": 0, - "permission_overwrites": [], - "parent_id": null, - "nsfw": false, - "name": "hey", - "last_message_id": "3", - "id": "2", - "guild_id": "1", - "guild_hashes": { - "version": 1, - "roles": { - "hash": "aaaaaaaaaaa" - }, - "metadata": { - "hash": "bbbbbbbbbbb" - }, - "channels": { - "hash": "ccccccccccc" - } - }, - "unknown_field": "the deserializer should skip unknown field names", - }); - let value = Channel { application_id: None, applied_tags: None, @@ -255,7 +230,50 @@ mod tests { video_quality_mode: None, }; - assert_eq!(value, serde_json::from_value(input).unwrap()); + serde_test::assert_de_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 17, + }, + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("type"), + Token::U8(u8::from(ChannelType::GuildText)), + Token::Str("last_message_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::Str("name"), + Token::Some, + Token::Str("hey"), + Token::Str("nsfw"), + Token::Some, + Token::Bool(false), + Token::Str("permission_overwrites"), + Token::Some, + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("position"), + Token::Some, + Token::I32(0), + Token::Str("rate_limit_per_user"), + Token::Some, + Token::U16(0), + Token::Str("topic"), + Token::Some, + Token::Str("a"), + Token::Str("unknown_field"), + Token::Str("unknown value"), + Token::StructEnd, + ], + ); } #[test] @@ -296,19 +314,35 @@ mod tests { user_limit: None, video_quality_mode: None, }; - let permission_overwrites: Vec = Vec::new(); - assert_eq!( - value, - serde_json::from_value(serde_json::json!({ - "id": "1", - "guild_id": Some("2"), - "name": "foo", - "permission_overwrites": permission_overwrites, - "position": 3, - "type": 4, - })) - .unwrap() + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 6, + }, + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("type"), + Token::U8(u8::from(ChannelType::GuildCategory)), + Token::Str("name"), + Token::Some, + Token::Str("foo"), + Token::Str("permission_overwrites"), + Token::Some, + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("position"), + Token::Some, + Token::I32(3), + Token::StructEnd, + ], ); } @@ -350,30 +384,56 @@ mod tests { user_limit: None, video_quality_mode: None, }; - let permission_overwrites: Vec = Vec::new(); - assert_eq!( - value, - serde_json::from_value(serde_json::json!({ - "id": "1", - "guild_id": "2", - "name": "news", - "nsfw": true, - "last_message_id": "4", - "parent_id": "5", - "permission_overwrites": permission_overwrites, - "position": 3, - "topic": "a news channel", - "type": ChannelType::GuildAnnouncement, - })) - .unwrap() + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 10, + }, + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("type"), + Token::U8(u8::from(ChannelType::GuildAnnouncement)), + Token::Str("last_message_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("4"), + Token::Str("name"), + Token::Some, + Token::Str("news"), + Token::Str("nsfw"), + Token::Some, + Token::Bool(true), + Token::Str("parent_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("permission_overwrites"), + Token::Some, + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("position"), + Token::Some, + Token::I32(3), + Token::Str("topic"), + Token::Some, + Token::Str("a news channel"), + Token::StructEnd, + ], ); } + #[allow(clippy::too_many_lines)] #[test] fn guild_announcement_thread_deserialization() { let timestamp = Timestamp::from_secs(1_632_074_792).expect("non zero"); - let formatted = timestamp.iso_8601().to_string(); let value = Channel { application_id: None, @@ -426,39 +486,95 @@ mod tests { video_quality_mode: None, }; - assert_eq!( - value, - serde_json::from_value(serde_json::json!({ - "id": "6", - "guild_id": "1", - "type": ChannelType::AnnouncementThread, - "last_message_id": "3", - "member": { - "flags": 0, - "id": "4", - "join_timestamp": formatted, - "user_id": "5", + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 14, + }, + Token::Str("default_auto_archive_duration"), + Token::Some, + Token::U16(AutoArchiveDuration::Hour.number()), + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::Str("type"), + Token::U8(u8::from(ChannelType::AnnouncementThread)), + Token::Str("last_message_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::Str("member"), + Token::Some, + Token::Struct { + name: "ThreadMember", + len: 4, }, - "default_auto_archive_duration": 60, - "member_count": 50, - "message_count": 50, - "name": "newsthread", - "newly_created": true, - "owner_id": "5", - "parent_id": "2", - "rate_limit_per_user": 1000, - "thread_metadata": { - "archive_timestamp": formatted, - "archived": false, - "auto_archive_duration": AutoArchiveDuration::Day, - "create_timestamp": formatted, - "locked": false - } - })) - .unwrap() - ) + Token::Str("flags"), + Token::U64(0), + Token::Str("id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("4"), + Token::Str("join_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("user_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::StructEnd, + Token::Str("member_count"), + Token::Some, + Token::U8(50), + Token::Str("message_count"), + Token::Some, + Token::U32(50), + Token::Str("name"), + Token::Some, + Token::Str("newsthread"), + Token::Str("newly_created"), + Token::Some, + Token::Bool(true), + Token::Str("owner_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("parent_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("rate_limit_per_user"), + Token::Some, + Token::U16(1000), + Token::Str("thread_metadata"), + Token::Some, + Token::Struct { + name: "ThreadMetadata", + len: 5, + }, + Token::Str("archived"), + Token::Bool(false), + Token::Str("auto_archive_duration"), + Token::U16(AutoArchiveDuration::Day.number()), + Token::Str("archive_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("create_timestamp"), + Token::Some, + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("locked"), + Token::Bool(false), + Token::StructEnd, + Token::StructEnd, + ], + ); } + #[allow(clippy::too_many_lines)] #[test] fn public_thread_deserialization() { let timestamp = Timestamp::from_secs(1_632_074_792).expect("non zero"); @@ -514,43 +630,98 @@ mod tests { video_quality_mode: None, }; - assert_eq!( - value, - serde_json::from_value(serde_json::json!({ - "id": "6", - "guild_id": "1", - "type": ChannelType::PublicThread, - "last_message_id": "3", - "member": { - "flags": 0, - "id": "4", - "join_timestamp": timestamp, - "user_id": "5", + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 14, + }, + Token::Str("default_auto_archive_duration"), + Token::Some, + Token::U16(AutoArchiveDuration::Hour.number()), + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::Str("type"), + Token::U8(u8::from(ChannelType::PublicThread)), + Token::Str("last_message_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::Str("member"), + Token::Some, + Token::Struct { + name: "ThreadMember", + len: 4, + }, + Token::Str("flags"), + Token::U64(0), + Token::Str("id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("4"), + Token::Str("join_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("user_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::StructEnd, + Token::Str("member_count"), + Token::Some, + Token::U8(50), + Token::Str("message_count"), + Token::Some, + Token::U32(50), + Token::Str("name"), + Token::Some, + Token::Str("publicthread"), + Token::Str("newly_created"), + Token::Some, + Token::Bool(true), + Token::Str("owner_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("parent_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("rate_limit_per_user"), + Token::Some, + Token::U16(1000), + Token::Str("thread_metadata"), + Token::Some, + Token::Struct { + name: "ThreadMetadata", + len: 5, }, - "default_auto_archive_duration": 60, - "member_count": 50, - "message_count": 50, - "name": "publicthread", - "newly_created": true, - "owner_id": "5", - "parent_id": "2", - "rate_limit_per_user": 1000, - "thread_metadata": { - "archive_timestamp": timestamp, - "archived": false, - "auto_archive_duration": AutoArchiveDuration::Day, - "create_timestamp": timestamp, - "locked": false - } - })) - .unwrap() - ) + Token::Str("archived"), + Token::Bool(false), + Token::Str("auto_archive_duration"), + Token::U16(AutoArchiveDuration::Day.number()), + Token::Str("archive_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("create_timestamp"), + Token::Some, + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("locked"), + Token::Bool(false), + Token::StructEnd, + Token::StructEnd, + ], + ); } + #[allow(clippy::too_many_lines)] #[test] fn private_thread_deserialization() { let timestamp = Timestamp::from_secs(1_632_074_792).expect("non zero"); - let formatted = timestamp.iso_8601().to_string(); let value = Channel { application_id: None, @@ -608,45 +779,112 @@ mod tests { video_quality_mode: None, }; - assert_eq!( - value, - serde_json::from_value(serde_json::json!({ - "id": "6", - "guild_id": "1", - "type": ChannelType::PrivateThread, - "last_message_id": "3", - "member": { - "flags": 0, - "id": "4", - "join_timestamp": formatted, - "user_id": "5", + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "Channel", + len: 16, + }, + Token::Str("default_auto_archive_duration"), + Token::Some, + Token::U16(AutoArchiveDuration::Hour.number()), + Token::Str("guild_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::Str("invitable"), + Token::Some, + Token::Bool(true), + Token::Str("type"), + Token::U8(u8::from(ChannelType::PrivateThread)), + Token::Str("last_message_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::Str("member"), + Token::Some, + Token::Struct { + name: "ThreadMember", + len: 4, }, - "default_auto_archive_duration": 60, - "invitable": true, - "member_count": 50, - "message_count": 50, - "name": "privatethread", - "newly_created": true, - "owner_id": "5", - "parent_id": "2", - "rate_limit_per_user": 1000, - "thread_metadata": { - "archive_timestamp": formatted, - "archived": false, - "auto_archive_duration": AutoArchiveDuration::Day, - "create_timestamp": formatted, - "locked": false + Token::Str("flags"), + Token::U64(0), + Token::Str("id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("4"), + Token::Str("join_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("user_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::StructEnd, + Token::Str("member_count"), + Token::Some, + Token::U8(50), + Token::Str("message_count"), + Token::Some, + Token::U32(50), + Token::Str("name"), + Token::Some, + Token::Str("privatethread"), + Token::Str("newly_created"), + Token::Some, + Token::Bool(true), + Token::Str("owner_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("parent_id"), + Token::Some, + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("permission_overwrites"), + Token::Some, + Token::Seq { len: Some(1) }, + Token::Struct { + name: "PermissionOverwrite", + len: 4, }, - "permission_overwrites": [ - { - "allow": "0", - "deny": "0", - "type": 1, - "id": "5" - } - ] - })) - .unwrap() - ) + Token::Str("allow"), + Token::Str("0"), + Token::Str("deny"), + Token::Str("0"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("type"), + Token::U8(u8::from(PermissionOverwriteType::Member)), + Token::StructEnd, + Token::SeqEnd, + Token::Str("rate_limit_per_user"), + Token::Some, + Token::U16(1000), + Token::Str("thread_metadata"), + Token::Some, + Token::Struct { + name: "ThreadMetadata", + len: 5, + }, + Token::Str("archived"), + Token::Bool(false), + Token::Str("auto_archive_duration"), + Token::U16(AutoArchiveDuration::Day.number()), + Token::Str("archive_timestamp"), + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("create_timestamp"), + Token::Some, + Token::Str("2021-09-19T18:06:32.000000+00:00"), + Token::Str("locked"), + Token::Bool(false), + Token::StructEnd, + Token::StructEnd, + ], + ); } } diff --git a/twilight-model/src/gateway/event/shard.rs b/twilight-model/src/gateway/event/shard.rs index d5c94c0839e..66b70f3e030 100644 --- a/twilight-model/src/gateway/event/shard.rs +++ b/twilight-model/src/gateway/event/shard.rs @@ -212,7 +212,9 @@ mod tests { #[test] fn payload() { - let value = Payload { bytes: vec![1, 2] }; + let value = Payload { + bytes: Vec::from([1, 2]), + }; serde_test::assert_tokens( &value, @@ -311,7 +313,9 @@ mod tests { ShardEvent::Identifying(_) )); - let payload = Event::ShardPayload(Payload { bytes: vec![1, 2] }); + let payload = Event::ShardPayload(Payload { + bytes: Vec::from([1, 2]), + }); assert!(matches!( payload.try_into().unwrap(), ShardEvent::Payload(_) diff --git a/twilight-model/src/gateway/payload/incoming/member_add.rs b/twilight-model/src/gateway/payload/incoming/member_add.rs index 7d9a39f7d70..6da7d0438e6 100644 --- a/twilight-model/src/gateway/payload/incoming/member_add.rs +++ b/twilight-model/src/gateway/payload/incoming/member_add.rs @@ -39,7 +39,7 @@ mod tests { nick: None, pending: true, premium_since: None, - roles: vec![], + roles: Vec::new(), user: User { id: Id::new(2), accent_color: None, diff --git a/twilight-model/src/gateway/payload/incoming/member_chunk.rs b/twilight-model/src/gateway/payload/incoming/member_chunk.rs index d109d4d2726..acfb5fe82a3 100644 --- a/twilight-model/src/gateway/payload/incoming/member_chunk.rs +++ b/twilight-model/src/gateway/payload/incoming/member_chunk.rs @@ -194,7 +194,7 @@ impl<'de> Deserialize<'de> for MemberChunk { #[cfg(test)] mod tests { - use super::super::MemberChunk; + use super::MemberChunk; use crate::{ gateway::presence::{ClientStatus, Presence, Status, UserOrId}, guild::Member, @@ -203,115 +203,17 @@ mod tests { user::{User, UserFlags}, util::datetime::{Timestamp, TimestampParseError}, }; + use serde_test::Token; use std::str::FromStr; #[allow(clippy::too_many_lines)] #[test] fn simple_member_chunk() -> Result<(), TimestampParseError> { - let joined_at = Timestamp::from_str("2020-04-04T04:04:04.000000+00:00")?; - - let input = serde_json::json!({ - "chunk_count": 1, - "chunk_index": 0, - "guild_id": "1", - "members": [{ - "communication_disabled_until": null, - "deaf": false, - "hoisted_role": "6", - "joined_at": "2020-04-04T04:04:04.000000+00:00", - "mute": false, - "nick": "chunk", - "pending": true, - "roles": ["6"], - "user": { - "avatar": image_hash::AVATAR_INPUT, - "discriminator": "0001", - "id": "5", - "public_flags": 131_072, - "username": "test", - }, - }, { - "communication_disabled_until": null, - "deaf": false, - "hoisted_role": "6", - "joined_at": "2020-04-04T04:04:04.000000+00:00", - "mute": false, - "nick": "chunk", - "roles": ["6"], - "user": { - "avatar": image_hash::AVATAR_INPUT, - "discriminator": "0001", - "id": "6", - "username": "test", - }, - }, { - "communication_disabled_until": null, - "deaf": false, - "hoisted_role": "6", - "joined_at": "2020-04-04T04:04:04.000000+00:00", - "mute": false, - "nick": "chunk", - "roles": ["6"], - "user": { - "avatar": image_hash::AVATAR_INPUT, - "bot": true, - "discriminator": "0001", - "id": "3", - "username": "test", - }, - }, { - "communication_disabled_until": null, - "deaf": false, - "hoisted_role": "6", - "joined_at": "2020-04-04T04:04:04.000000+00:00", - "mute": false, - "nick": "chunk", - "roles": [ - "6", - "7", - ], - "user": { - "avatar": image_hash::AVATAR_INPUT, - "bot": true, - "discriminator": "0001", - "id": "2", - "username": "test", - }, - }], - "presences": [{ - "activities": [], - "client_status": { - "web": "online", - }, - "guild_id": "1", - "status": "online", - "user": { - "id": "2", - }, - }, { - "activities": [], - "client_status": { - "web": "online", - }, - "guild_id": "1", - "status": "online", - "user": { - "id": "3", - }, - }, { - "activities": [], - "client_status": { - "desktop": "dnd", - }, - "guild_id": "1", - "status": "dnd", - "user": { - "id": "5", - }, - }], - }); + const JOINED_AT_INPUT: &str = "2020-04-04T04:04:04.000000+00:00"; - let expected = MemberChunk { + let joined_at = Timestamp::from_str(JOINED_AT_INPUT)?; + + let value = MemberChunk { chunk_count: 1, chunk_index: 0, guild_id: Id::new(1), @@ -326,7 +228,7 @@ mod tests { nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6), Id::new(7)], + roles: Vec::from([Id::new(6), Id::new(7)]), user: User { id: Id::new(2), accent_color: None, @@ -355,7 +257,7 @@ mod tests { nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6)], + roles: Vec::from([Id::new(6)]), user: User { id: Id::new(3), accent_color: None, @@ -384,7 +286,7 @@ mod tests { nick: Some("chunk".to_owned()), pending: true, premium_since: None, - roles: vec![Id::new(6)], + roles: Vec::from([Id::new(6)]), user: User { id: Id::new(5), accent_color: None, @@ -413,7 +315,7 @@ mod tests { nick: Some("chunk".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(6)], + roles: Vec::from([Id::new(6)]), user: User { id: Id::new(6), accent_color: None, @@ -472,20 +374,340 @@ mod tests { ]), }; - let actual = serde_json::from_value::(input).unwrap(); - assert_eq!(expected.chunk_count, actual.chunk_count); - assert_eq!(expected.chunk_index, actual.chunk_index); - assert_eq!(expected.guild_id, actual.guild_id); - assert_eq!(expected.nonce, actual.nonce); - assert_eq!(expected.not_found, actual.not_found); - - for member in &actual.members { - assert!(expected.members.iter().any(|m| m == member)); - } - - for presences in &actual.presences { - assert!(expected.presences.iter().any(|p| p == presences)); - } + serde_test::assert_tokens( + &value, + &[ + Token::Struct { + name: "MemberChunk", + len: 6, + }, + Token::Str("chunk_count"), + Token::U32(1), + Token::Str("chunk_index"), + Token::U32(0), + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("members"), + Token::Seq { len: Some(4) }, + Token::Struct { + name: "Member", + len: 9, + }, + Token::Str("communication_disabled_until"), + Token::None, + Token::Str("deaf"), + Token::Bool(false), + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("joined_at"), + Token::Str(JOINED_AT_INPUT), + Token::Str("mute"), + Token::Bool(false), + Token::Str("nick"), + Token::Some, + Token::Str("chunk"), + Token::Str("pending"), + Token::Bool(false), + Token::Str("roles"), + Token::Seq { len: Some(2) }, + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("7"), + Token::SeqEnd, + Token::Str("user"), + Token::Struct { + name: "User", + len: 7, + }, + Token::Str("accent_color"), + Token::None, + Token::Str("avatar"), + Token::Some, + Token::Str(image_hash::AVATAR_INPUT), + Token::Str("banner"), + Token::None, + Token::Str("bot"), + Token::Bool(true), + Token::Str("discriminator"), + Token::Str("0001"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::Str("username"), + Token::Str("test"), + Token::StructEnd, + Token::StructEnd, + Token::Struct { + name: "Member", + len: 9, + }, + Token::Str("communication_disabled_until"), + Token::None, + Token::Str("deaf"), + Token::Bool(false), + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("joined_at"), + Token::Str(JOINED_AT_INPUT), + Token::Str("mute"), + Token::Bool(false), + Token::Str("nick"), + Token::Some, + Token::Str("chunk"), + Token::Str("pending"), + Token::Bool(false), + Token::Str("roles"), + Token::Seq { len: Some(1) }, + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::SeqEnd, + Token::Str("user"), + Token::Struct { + name: "User", + len: 7, + }, + Token::Str("accent_color"), + Token::None, + Token::Str("avatar"), + Token::Some, + Token::Str(image_hash::AVATAR_INPUT), + Token::Str("banner"), + Token::None, + Token::Str("bot"), + Token::Bool(true), + Token::Str("discriminator"), + Token::Str("0001"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::Str("username"), + Token::Str("test"), + Token::StructEnd, + Token::StructEnd, + Token::Struct { + name: "Member", + len: 9, + }, + Token::Str("communication_disabled_until"), + Token::None, + Token::Str("deaf"), + Token::Bool(false), + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("joined_at"), + Token::Str(JOINED_AT_INPUT), + Token::Str("mute"), + Token::Bool(false), + Token::Str("nick"), + Token::Some, + Token::Str("chunk"), + Token::Str("pending"), + Token::Bool(true), + Token::Str("roles"), + Token::Seq { len: Some(1) }, + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::SeqEnd, + Token::Str("user"), + Token::Struct { + name: "User", + len: 8, + }, + Token::Str("accent_color"), + Token::None, + Token::Str("avatar"), + Token::Some, + Token::Str(image_hash::AVATAR_INPUT), + Token::Str("banner"), + Token::None, + Token::Str("bot"), + Token::Bool(false), + Token::Str("discriminator"), + Token::Str("0001"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::Str("username"), + Token::Str("test"), + Token::Str("public_flags"), + Token::Some, + Token::U64(131_072), + Token::StructEnd, + Token::StructEnd, + Token::Struct { + name: "Member", + len: 9, + }, + Token::Str("communication_disabled_until"), + Token::None, + Token::Str("deaf"), + Token::Bool(false), + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("joined_at"), + Token::Str(JOINED_AT_INPUT), + Token::Str("mute"), + Token::Bool(false), + Token::Str("nick"), + Token::Some, + Token::Str("chunk"), + Token::Str("pending"), + Token::Bool(false), + Token::Str("roles"), + Token::Seq { len: Some(1) }, + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::SeqEnd, + Token::Str("user"), + Token::Struct { + name: "User", + len: 7, + }, + Token::Str("accent_color"), + Token::None, + Token::Str("avatar"), + Token::Some, + Token::Str(image_hash::AVATAR_INPUT), + Token::Str("banner"), + Token::None, + Token::Str("bot"), + Token::Bool(false), + Token::Str("discriminator"), + Token::Str("0001"), + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("6"), + Token::Str("username"), + Token::Str("test"), + Token::StructEnd, + Token::StructEnd, + Token::SeqEnd, + Token::Str("not_found"), + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("presences"), + Token::Seq { len: Some(3) }, + Token::Struct { + name: "Presence", + len: 5, + }, + Token::Str("activities"), + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("client_status"), + Token::Struct { + name: "ClientStatus", + len: 1, + }, + Token::Str("web"), + Token::Some, + Token::UnitVariant { + name: "Status", + variant: "online", + }, + Token::StructEnd, + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("status"), + Token::UnitVariant { + name: "Status", + variant: "online", + }, + Token::Str("user"), + Token::Struct { + name: "UserOrId", + len: 1, + }, + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("2"), + Token::StructEnd, + Token::StructEnd, + Token::Struct { + name: "Presence", + len: 5, + }, + Token::Str("activities"), + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("client_status"), + Token::Struct { + name: "ClientStatus", + len: 1, + }, + Token::Str("web"), + Token::Some, + Token::UnitVariant { + name: "Status", + variant: "online", + }, + Token::StructEnd, + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("status"), + Token::UnitVariant { + name: "Status", + variant: "online", + }, + Token::Str("user"), + Token::Struct { + name: "UserOrId", + len: 1, + }, + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("3"), + Token::StructEnd, + Token::StructEnd, + Token::Struct { + name: "Presence", + len: 5, + }, + Token::Str("activities"), + Token::Seq { len: Some(0) }, + Token::SeqEnd, + Token::Str("client_status"), + Token::Struct { + name: "ClientStatus", + len: 1, + }, + Token::Str("desktop"), + Token::Some, + Token::UnitVariant { + name: "Status", + variant: "dnd", + }, + Token::StructEnd, + Token::Str("guild_id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("1"), + Token::Str("status"), + Token::UnitVariant { + name: "Status", + variant: "dnd", + }, + Token::Str("user"), + Token::Struct { + name: "UserOrId", + len: 1, + }, + Token::Str("id"), + Token::NewtypeStruct { name: "Id" }, + Token::Str("5"), + Token::StructEnd, + Token::StructEnd, + Token::SeqEnd, + Token::StructEnd, + ], + ); Ok(()) } diff --git a/twilight-model/src/gateway/payload/incoming/member_update.rs b/twilight-model/src/gateway/payload/incoming/member_update.rs index f6ee4722feb..d054629c8e0 100644 --- a/twilight-model/src/gateway/payload/incoming/member_update.rs +++ b/twilight-model/src/gateway/payload/incoming/member_update.rs @@ -56,7 +56,7 @@ mod tests { nick: Some("Twilight".to_string()), pending: false, premium_since: None, - roles: vec![], + roles: Vec::new(), user: User { accent_color: None, banner: None, diff --git a/twilight-model/src/gateway/payload/incoming/ready.rs b/twilight-model/src/gateway/payload/incoming/ready.rs index 5791c51153e..62d8581e0b4 100644 --- a/twilight-model/src/gateway/payload/incoming/ready.rs +++ b/twilight-model/src/gateway/payload/incoming/ready.rs @@ -28,7 +28,7 @@ mod tests { #[test] #[allow(clippy::too_many_lines)] fn test_ready() { - let guilds = vec![ + let guilds = Vec::from([ UnavailableGuild { id: Id::new(1), unavailable: true, @@ -37,7 +37,7 @@ mod tests { id: Id::new(2), unavailable: true, }, - ]; + ]); let ready = Ready { application: PartialApplication { diff --git a/twilight-model/src/gateway/payload/incoming/thread_members_update.rs b/twilight-model/src/gateway/payload/incoming/thread_members_update.rs index 8224099efd1..5538cd09b07 100644 --- a/twilight-model/src/gateway/payload/incoming/thread_members_update.rs +++ b/twilight-model/src/gateway/payload/incoming/thread_members_update.rs @@ -163,7 +163,7 @@ mod tests { url: None, }; let presence = Presence { - activities: vec![activity], + activities: Vec::from([activity]), client_status: ClientStatus { desktop: Some(Status::Online), mobile: None, @@ -177,18 +177,18 @@ mod tests { let join_timestamp = Timestamp::from_str(JOIN_TIMESTAMP).expect("timestamp error"); let value = ThreadMembersUpdate { - added_members: vec![ThreadMember { + added_members: Vec::from([ThreadMember { flags: 1, id: Some(Id::new(123)), join_timestamp, member: Some(member), presence: Some(presence), user_id: Some(Id::new(3)), - }], + }]), guild_id: Id::new(2), id: Id::new(4), member_count: 8, - removed_member_ids: vec![], + removed_member_ids: Vec::new(), }; serde_test::assert_de_tokens( diff --git a/twilight-model/src/gateway/payload/incoming/typing_start.rs b/twilight-model/src/gateway/payload/incoming/typing_start.rs index 4e227b4e5db..4f1483a5382 100644 --- a/twilight-model/src/gateway/payload/incoming/typing_start.rs +++ b/twilight-model/src/gateway/payload/incoming/typing_start.rs @@ -180,7 +180,7 @@ mod tests { nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(4)], + roles: Vec::from([Id::new(4)]), user: User { id: Id::new(3), accent_color: None, diff --git a/twilight-model/src/gateway/payload/incoming/voice_state_update.rs b/twilight-model/src/gateway/payload/incoming/voice_state_update.rs index 596e8a1832b..2d7af354784 100644 --- a/twilight-model/src/gateway/payload/incoming/voice_state_update.rs +++ b/twilight-model/src/gateway/payload/incoming/voice_state_update.rs @@ -51,7 +51,7 @@ mod tests { nick: None, pending: false, premium_since: None, - roles: vec![Id::new(4)], + roles: Vec::from([Id::new(4)]), user: User { id: Id::new(1), accent_color: None, @@ -191,7 +191,7 @@ mod tests { nick: Some("Twilight".to_string()), pending: false, premium_since: None, - roles: vec![Id::new(123), Id::new(124)], + roles: Vec::from([Id::new(123), Id::new(124)]), user: User { id: Id::new(1_234_123_123_123), accent_color: None, diff --git a/twilight-model/src/gateway/payload/outgoing/request_guild_members.rs b/twilight-model/src/gateway/payload/outgoing/request_guild_members.rs index ed7b4d7a9a9..d4f1206329f 100644 --- a/twilight-model/src/gateway/payload/outgoing/request_guild_members.rs +++ b/twilight-model/src/gateway/payload/outgoing/request_guild_members.rs @@ -233,7 +233,7 @@ impl RequestGuildMembersBuilder { /// # fn main() -> Result<(), Box> { /// let request = RequestGuildMembers::builder(Id::new(1)) /// .nonce("test") - /// .user_ids(vec![Id::new(2), Id::new(2)])?; + /// .user_ids(Vec::from([Id::new(2), Id::new(2)]))?; /// /// assert!(matches!(request.d.user_ids, Some(RequestGuildMemberId::Multiple(ids)) if ids.len() == 2)); /// # Ok(()) } diff --git a/twilight-model/src/gateway/presence/mod.rs b/twilight-model/src/gateway/presence/mod.rs index 5107e72f510..b53dadc4929 100644 --- a/twilight-model/src/gateway/presence/mod.rs +++ b/twilight-model/src/gateway/presence/mod.rs @@ -204,7 +204,7 @@ mod tests { url: None, }; let value = Presence { - activities: vec![activity], + activities: Vec::from([activity]), client_status: ClientStatus { desktop: Some(Status::Online), mobile: None, @@ -306,7 +306,7 @@ mod tests { }]"#; let expected = Vec::from([Presence { - activities: vec![], + activities: Vec::new(), client_status: ClientStatus { desktop: Some(Status::Online), mobile: None, diff --git a/twilight-model/src/gateway/reaction.rs b/twilight-model/src/gateway/reaction.rs index 1eb9a3ddd48..f345502dca9 100644 --- a/twilight-model/src/gateway/reaction.rs +++ b/twilight-model/src/gateway/reaction.rs @@ -192,7 +192,7 @@ mod tests { nick: Some("typing".to_owned()), pending: false, premium_since: None, - roles: vec![Id::new(5)], + roles: Vec::from([Id::new(5)]), user: User { accent_color: None, avatar: Some(image_hash::AVATAR), diff --git a/twilight-model/src/guild/emoji.rs b/twilight-model/src/guild/emoji.rs index fac4c409665..51cab39708e 100644 --- a/twilight-model/src/guild/emoji.rs +++ b/twilight-model/src/guild/emoji.rs @@ -120,7 +120,7 @@ mod tests { managed: false, name: "test".to_owned(), require_colons: true, - roles: vec![Id::new(1)], + roles: Vec::from([Id::new(1)]), user: Some(User { accent_color: None, avatar: None, diff --git a/twilight-model/src/guild/invite/guild.rs b/twilight-model/src/guild/invite/guild.rs index 4f1e5a2a706..d56ac8e2bf7 100644 --- a/twilight-model/src/guild/invite/guild.rs +++ b/twilight-model/src/guild/invite/guild.rs @@ -50,7 +50,7 @@ mod tests { let value = InviteGuild { banner: Some(image_hash::BANNER), description: Some("a description".to_owned()), - features: vec!["a feature".to_owned()], + features: Vec::from(["a feature".to_owned()]), icon: Some(image_hash::ICON), id: Id::new(1), name: "guild name".to_owned(), @@ -60,7 +60,7 @@ mod tests { verification_level: VerificationLevel::Medium, welcome_screen: Some(WelcomeScreen { description: Some("welcome description".to_owned()), - welcome_channels: vec![ + welcome_channels: Vec::from([ WelcomeScreenChannel { channel_id: Id::new(123), description: "channel description".to_owned(), @@ -73,7 +73,7 @@ mod tests { emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, - ], + ]), }), }; diff --git a/twilight-model/src/guild/invite/mod.rs b/twilight-model/src/guild/invite/mod.rs index 1df73c0eef6..16ba77f46c7 100644 --- a/twilight-model/src/guild/invite/mod.rs +++ b/twilight-model/src/guild/invite/mod.rs @@ -167,7 +167,7 @@ mod tests { guild: Some(InviteGuild { banner: Some(image_hash::BANNER), description: Some("a description".to_owned()), - features: vec!["a feature".to_owned()], + features: Vec::from(["a feature".to_owned()]), icon: Some(image_hash::ICON), id: Id::new(1), name: "guild name".to_owned(), @@ -177,7 +177,7 @@ mod tests { verification_level: VerificationLevel::Medium, welcome_screen: Some(WelcomeScreen { description: Some("welcome description".to_owned()), - welcome_channels: vec![ + welcome_channels: Vec::from([ WelcomeScreenChannel { channel_id: Id::new(123), description: "channel description".to_owned(), @@ -190,7 +190,7 @@ mod tests { emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, - ], + ]), }), }), inviter: Some(User { diff --git a/twilight-model/src/guild/invite/welcome_screen.rs b/twilight-model/src/guild/invite/welcome_screen.rs index fb46bcd4903..d411d93ba41 100644 --- a/twilight-model/src/guild/invite/welcome_screen.rs +++ b/twilight-model/src/guild/invite/welcome_screen.rs @@ -34,7 +34,7 @@ mod tests { fn welcome_screen() { let value = WelcomeScreen { description: Some("welcome description".to_owned()), - welcome_channels: vec![ + welcome_channels: Vec::from([ WelcomeScreenChannel { channel_id: Id::new(123), description: "channel description".to_owned(), @@ -47,7 +47,7 @@ mod tests { emoji_id: Some(Id::new(789)), emoji_name: Some("custom_name".to_owned()), }, - ], + ]), }; serde_test::assert_tokens( diff --git a/twilight-model/src/guild/partial_member.rs b/twilight-model/src/guild/partial_member.rs index 60b8845b7e1..a2e733f3626 100644 --- a/twilight-model/src/guild/partial_member.rs +++ b/twilight-model/src/guild/partial_member.rs @@ -52,7 +52,7 @@ mod tests { nick: Some("a nickname".to_owned()), permissions: None, premium_since: None, - roles: vec![Id::new(1)], + roles: Vec::from([Id::new(1)]), user: None, }; diff --git a/twilight-model/src/guild/preview.rs b/twilight-model/src/guild/preview.rs index 2c8a4b84ce2..2a8b6c33b55 100644 --- a/twilight-model/src/guild/preview.rs +++ b/twilight-model/src/guild/preview.rs @@ -35,7 +35,7 @@ mod tests { approximate_presence_count: 500, description: Some("guild description".to_owned()), discovery_splash: Some(image_hash::SPLASH), - emojis: vec![Emoji { + emojis: Vec::from([Emoji { animated: false, available: true, id: Id::new(2), @@ -44,8 +44,8 @@ mod tests { require_colons: true, roles: Vec::new(), user: None, - }], - features: vec!["a feature".to_owned()], + }]), + features: Vec::from(["a feature".to_owned()]), id: Id::new(1), name: "guild name".to_owned(), icon: Some(image_hash::ICON), diff --git a/twilight-model/src/guild/template/mod.rs b/twilight-model/src/guild/template/mod.rs index 10c6ff860af..023b384d436 100644 --- a/twilight-model/src/guild/template/mod.rs +++ b/twilight-model/src/guild/template/mod.rs @@ -229,7 +229,7 @@ mod tests { nsfw: Some(false), owner_id: None, parent_id: None, - permission_overwrites: Some(vec![]), + permission_overwrites: Some(Vec::new()), position: Some(0), rate_limit_per_user: None, recipients: None, @@ -265,7 +265,7 @@ mod tests { nsfw: Some(false), owner_id: None, parent_id: Some(Id::new(1)), - permission_overwrites: Some(vec![ + permission_overwrites: Some(Vec::from([ PermissionOverwrite { allow: Permissions::from_bits(0).unwrap(), deny: Permissions::from_bits(2048).unwrap(), @@ -278,7 +278,7 @@ mod tests { id: Id::new(2), kind: PermissionOverwriteType::Role, }, - ]), + ])), position: Some(0), rate_limit_per_user: Some(0), recipients: None, @@ -314,7 +314,7 @@ mod tests { nsfw: Some(false), owner_id: None, parent_id: None, - permission_overwrites: Some(vec![]), + permission_overwrites: Some(Vec::new()), position: Some(0), rate_limit_per_user: None, recipients: None, @@ -350,7 +350,7 @@ mod tests { nsfw: Some(false), owner_id: None, parent_id: Some(Id::new(3)), - permission_overwrites: Some(vec![]), + permission_overwrites: Some(Vec::new()), position: Some(0), rate_limit_per_user: None, recipients: None, @@ -367,7 +367,7 @@ mod tests { icon_hash: None, name: "server name".into(), preferred_locale: "en-US".into(), - roles: vec![ + roles: Vec::from([ TemplateRole { color: 0, hoist: false, @@ -412,7 +412,7 @@ mod tests { | Permissions::CHANGE_NICKNAME, tags: None, }, - ], + ]), system_channel_flags: SystemChannelFlags::empty(), system_channel_id: Some(Id::new(2)), verification_level: VerificationLevel::None, diff --git a/twilight-model/src/oauth/application.rs b/twilight-model/src/oauth/application.rs index f1054d6dc34..096f94399ed 100644 --- a/twilight-model/src/oauth/application.rs +++ b/twilight-model/src/oauth/application.rs @@ -126,7 +126,7 @@ mod tests { }), primary_sku_id: Some(Id::new(4)), privacy_policy_url: Some("https://privacypolicy".into()), - rpc_origins: vec!["one".to_owned()], + rpc_origins: Vec::from(["one".to_owned()]), slug: Some("app slug".to_owned()), tags: Some(Vec::from([ "ponies".to_owned(), diff --git a/twilight-model/src/oauth/team/member.rs b/twilight-model/src/oauth/team/member.rs index 115aeb93982..b10f9b715c4 100644 --- a/twilight-model/src/oauth/team/member.rs +++ b/twilight-model/src/oauth/team/member.rs @@ -23,7 +23,7 @@ mod tests { fn team_member() { let value = TeamMember { membership_state: TeamMembershipState::Accepted, - permissions: vec!["*".to_owned()], + permissions: Vec::from(["*".to_owned()]), team_id: Id::new(1), user: User { accent_color: None, diff --git a/twilight-model/src/user/current_user.rs b/twilight-model/src/user/current_user.rs index 62aba5ccf52..8a618dd96d4 100644 --- a/twilight-model/src/user/current_user.rs +++ b/twilight-model/src/user/current_user.rs @@ -82,7 +82,7 @@ mod tests { use serde_test::Token; fn user_tokens(discriminator_token: Token) -> Vec { - vec![ + Vec::from([ Token::Struct { name: "CurrentUser", len: 12, @@ -119,11 +119,11 @@ mod tests { Token::Some, Token::Bool(true), Token::StructEnd, - ] + ]) } fn user_tokens_complete(discriminator_token: Token) -> Vec { - vec![ + Vec::from([ Token::Struct { name: "CurrentUser", len: 14, @@ -166,7 +166,7 @@ mod tests { Token::Some, Token::Bool(true), Token::StructEnd, - ] + ]) } #[test] diff --git a/twilight-model/src/user/current_user_guild.rs b/twilight-model/src/user/current_user_guild.rs index 89cb7f56729..aeade09acef 100644 --- a/twilight-model/src/user/current_user_guild.rs +++ b/twilight-model/src/user/current_user_guild.rs @@ -50,7 +50,7 @@ mod tests { icon: Some(image_hash::ICON), owner: true, permissions: Permissions::from_bits_truncate(36_953_089), - features: vec!["a feature".to_owned()], + features: Vec::from(["a feature".to_owned()]), }; serde_test::assert_tokens( diff --git a/twilight-model/src/user/mod.rs b/twilight-model/src/user/mod.rs index c94262e236e..ec8f22147f1 100644 --- a/twilight-model/src/user/mod.rs +++ b/twilight-model/src/user/mod.rs @@ -188,7 +188,7 @@ mod tests { ); fn user_tokens(discriminator_token: Token) -> Vec { - vec![ + Vec::from([ Token::Struct { name: "User", len: 14, @@ -232,11 +232,11 @@ mod tests { Token::Some, Token::Bool(true), Token::StructEnd, - ] + ]) } fn user_tokens_complete(discriminator_token: Token) -> Vec { - vec![ + Vec::from([ Token::Struct { name: "User", len: 15, @@ -283,7 +283,7 @@ mod tests { Token::Some, Token::Bool(true), Token::StructEnd, - ] + ]) } #[test] diff --git a/twilight-model/src/user/profile.rs b/twilight-model/src/user/profile.rs index 9e362c46fca..eeb429f00a4 100644 --- a/twilight-model/src/user/profile.rs +++ b/twilight-model/src/user/profile.rs @@ -58,7 +58,7 @@ mod tests { use serde_test::Token; fn user_tokens(discriminator_token: Token) -> Vec { - vec![ + Vec::from([ Token::Struct { name: "UserProfile", len: 13, @@ -99,7 +99,7 @@ mod tests { Token::Some, Token::Bool(true), Token::StructEnd, - ] + ]) } #[test] diff --git a/twilight-util/src/builder/interaction_response_data.rs b/twilight-util/src/builder/interaction_response_data.rs index 017b813ce0d..e22fc0dce4e 100644 --- a/twilight-util/src/builder/interaction_response_data.rs +++ b/twilight-util/src/builder/interaction_response_data.rs @@ -31,7 +31,7 @@ use twilight_model::{ /// .components([component.clone()]) /// .build(); /// -/// assert_eq!(interaction_response_data.components, Some(vec![component])); +/// assert_eq!(interaction_response_data.components, Some(Vec::from([component]))); /// ``` #[derive(Clone, Debug)] #[must_use = "builders have no effect if unused"] @@ -227,10 +227,10 @@ mod tests { allowed_mentions: Some(allowed_mentions), attachments: None, choices: None, - components: Some(vec![component]), + components: Some(Vec::from([component])), content: Some("a content".to_owned()), custom_id: None, - embeds: Some(vec![embed]), + embeds: Some(Vec::from([embed])), flags: Some(MessageFlags::empty()), title: None, tts: Some(false),