diff --git a/src/http/client.rs b/src/http/client.rs index b336e5aef9f..d205ac9dbf9 100644 --- a/src/http/client.rs +++ b/src/http/client.rs @@ -239,7 +239,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await?; @@ -272,7 +272,7 @@ impl Http { role_id, user_id, }, - params: &[], + params: None, }) .await } @@ -302,7 +302,7 @@ impl Http { guild_id, user_id, }, - params: &[("delete_message_days", delete_message_days.to_string())], + params: Some(&[("delete_message_days", delete_message_days.to_string())]), }) .await } @@ -323,7 +323,7 @@ impl Http { route: Route::ChannelTyping { channel_id, }, - params: &[], + params: None, }) .await } @@ -352,7 +352,7 @@ impl Http { route: Route::GuildChannels { guild_id, }, - params: &[], + params: None, }) .await } @@ -369,7 +369,7 @@ impl Http { headers: audit_log_reason.map(reason_into_header), method: LightMethod::Post, route: Route::StageInstances, - params: &[], + params: None, }) .await } @@ -393,7 +393,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -415,7 +415,7 @@ impl Http { route: Route::ChannelThreads { channel_id, }, - params: &[], + params: None, }) .await } @@ -450,7 +450,7 @@ impl Http { route: Route::ChannelForumPosts { channel_id, }, - params: &[], + params: None, }) .await } @@ -476,7 +476,7 @@ impl Http { route: Route::GuildEmojis { guild_id, }, - params: &[], + params: None, }) .await } @@ -499,7 +499,7 @@ impl Http { application_id: self.try_application_id()?, token: interaction_token, }, - params: &[], + params: None, }; if files.is_empty() { @@ -534,7 +534,7 @@ impl Http { route: Route::Commands { application_id: self.try_application_id()?, }, - params: &[], + params: None, }) .await } @@ -552,7 +552,7 @@ impl Http { route: Route::Commands { application_id: self.try_application_id()?, }, - params: &[], + params: None, }) .await } @@ -572,7 +572,7 @@ impl Http { application_id: self.try_application_id()?, guild_id, }, - params: &[], + params: None, }) .await } @@ -617,7 +617,7 @@ impl Http { headers: None, method: LightMethod::Post, route: Route::Guilds, - params: &[], + params: None, }) .await } @@ -643,7 +643,7 @@ impl Http { application_id: self.try_application_id()?, guild_id, }, - params: &[], + params: None, }) .await } @@ -672,7 +672,7 @@ impl Http { guild_id, integration_id, }, - params: &[], + params: None, }) .await } @@ -699,7 +699,7 @@ impl Http { interaction_id, token: interaction_token, }, - params: &[], + params: None, }; if files.is_empty() { @@ -741,7 +741,7 @@ impl Http { route: Route::ChannelInvites { channel_id, }, - params: &[], + params: None, }) .await } @@ -765,7 +765,7 @@ impl Http { channel_id, target_id, }, - params: &[], + params: None, }) .await } @@ -780,7 +780,7 @@ impl Http { headers: None, method: LightMethod::Post, route: Route::UserMeDmChannels, - params: &[], + params: None, }) .await } @@ -802,7 +802,7 @@ impl Http { message_id, reaction: &reaction_type.as_data(), }, - params: &[], + params: None, }) .await } @@ -823,7 +823,7 @@ impl Http { route: Route::GuildRoles { guild_id, }, - params: &[], + params: None, }) .await?; @@ -856,7 +856,7 @@ impl Http { route: Route::GuildScheduledEvents { guild_id, }, - params: &[], + params: None, }) .await } @@ -885,7 +885,7 @@ impl Http { route: Route::GuildStickers { guild_id, }, - params: &[], + params: None, }) .await } @@ -915,7 +915,7 @@ impl Http { route: Route::Entitlements { application_id: self.try_application_id()?, }, - params: &[], + params: None, }) .await } @@ -962,7 +962,7 @@ impl Http { route: Route::ChannelWebhooks { channel_id, }, - params: &[], + params: None, }) .await } @@ -981,7 +981,7 @@ impl Http { route: Route::Channel { channel_id, }, - params: &[], + params: None, }) .await } @@ -1000,7 +1000,7 @@ impl Http { route: Route::StageInstance { channel_id, }, - params: &[], + params: None, }) .await } @@ -1023,7 +1023,7 @@ impl Http { guild_id, emoji_id, }, - params: &[], + params: None, }) .await } @@ -1044,7 +1044,7 @@ impl Http { token: interaction_token, message_id, }, - params: &[], + params: None, }) .await } @@ -1060,7 +1060,7 @@ impl Http { application_id: self.try_application_id()?, command_id, }, - params: &[], + params: None, }) .await } @@ -1075,7 +1075,7 @@ impl Http { route: Route::Guild { guild_id, }, - params: &[], + params: None, }) .await } @@ -1096,7 +1096,7 @@ impl Http { guild_id, command_id, }, - params: &[], + params: None, }) .await } @@ -1117,7 +1117,7 @@ impl Http { guild_id, integration_id, }, - params: &[], + params: None, }) .await } @@ -1136,7 +1136,7 @@ impl Http { route: Route::Invite { code, }, - params: &[], + params: None, }) .await } @@ -1157,7 +1157,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -1177,7 +1177,7 @@ impl Http { route: Route::ChannelMessagesBulkDelete { channel_id, }, - params: &[], + params: None, }) .await } @@ -1214,7 +1214,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -1236,7 +1236,7 @@ impl Http { message_id, reaction: &reaction_type.as_data(), }, - params: &[], + params: None, }) .await } @@ -1255,7 +1255,7 @@ impl Http { application_id: self.try_application_id()?, token: interaction_token, }, - params: &[], + params: None, }) .await } @@ -1276,7 +1276,7 @@ impl Http { channel_id, target_id, }, - params: &[], + params: None, }) .await } @@ -1300,7 +1300,7 @@ impl Http { user_id, reaction: &reaction_type.as_data(), }, - params: &[], + params: None, }) .await } @@ -1322,7 +1322,7 @@ impl Http { message_id, reaction: &reaction_type.as_data(), }, - params: &[], + params: None, }) .await } @@ -1343,7 +1343,7 @@ impl Http { guild_id, role_id, }, - params: &[], + params: None, }) .await } @@ -1368,7 +1368,7 @@ impl Http { guild_id, event_id, }, - params: &[], + params: None, }) .await } @@ -1391,7 +1391,7 @@ impl Http { guild_id, sticker_id, }, - params: &[], + params: None, }) .await } @@ -1408,7 +1408,7 @@ impl Http { application_id: self.try_application_id()?, entitlement_id, }, - params: &[], + params: None, }) .await } @@ -1445,7 +1445,7 @@ impl Http { route: Route::Webhook { webhook_id, }, - params: &[], + params: None, }) .await } @@ -1486,7 +1486,7 @@ impl Http { webhook_id, token, }, - params: &[], + params: None, }) .await } @@ -1508,7 +1508,7 @@ impl Http { route: Route::Channel { channel_id, }, - params: &[], + params: None, }) .await } @@ -1528,7 +1528,7 @@ impl Http { route: Route::StageInstance { channel_id, }, - params: &[], + params: None, }) .await } @@ -1554,7 +1554,7 @@ impl Http { guild_id, emoji_id, }, - params: &[], + params: None, }) .await } @@ -1581,7 +1581,7 @@ impl Http { token: interaction_token, message_id, }, - params: &[], + params: None, }; if new_attachments.is_empty() { @@ -1617,7 +1617,7 @@ impl Http { token: interaction_token, message_id, }, - params: &[], + params: None, }) .await } @@ -1643,7 +1643,7 @@ impl Http { application_id: self.try_application_id()?, command_id, }, - params: &[], + params: None, }) .await } @@ -1665,7 +1665,7 @@ impl Http { route: Route::Guild { guild_id, }, - params: &[], + params: None, }) .await } @@ -1693,7 +1693,7 @@ impl Http { guild_id, command_id, }, - params: &[], + params: None, }) .await } @@ -1721,7 +1721,7 @@ impl Http { guild_id, command_id, }, - params: &[], + params: None, }) .await } @@ -1742,7 +1742,7 @@ impl Http { route: Route::GuildChannels { guild_id, }, - params: &[], + params: None, }) .await } @@ -1769,7 +1769,7 @@ impl Http { route: Route::GuildMfa { guild_id, }, - params: &[], + params: None, }) .await .map(|mfa: GuildMfaLevel| mfa.level) @@ -1792,7 +1792,7 @@ impl Http { route: Route::GuildWidget { guild_id, }, - params: &[], + params: None, }) .await } @@ -1814,7 +1814,7 @@ impl Http { route: Route::GuildWelcomeScreen { guild_id, }, - params: &[], + params: None, }) .await } @@ -1839,7 +1839,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await?; @@ -1869,7 +1869,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }; if new_attachments.is_empty() { @@ -1902,7 +1902,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -1924,7 +1924,7 @@ impl Http { route: Route::GuildMemberMe { guild_id, }, - params: &[], + params: None, }) .await } @@ -1949,7 +1949,7 @@ impl Http { route: Route::GuildMemberMe { guild_id, }, - params: &[], + params: None, }) .await } @@ -1971,7 +1971,7 @@ impl Http { route: Route::ChannelFollowNews { channel_id: news_channel_id, }, - params: &[], + params: None, }) .await } @@ -1990,7 +1990,7 @@ impl Http { application_id: self.try_application_id()?, token: interaction_token, }, - params: &[], + params: None, }) .await } @@ -2015,7 +2015,7 @@ impl Http { application_id: self.try_application_id()?, token: interaction_token, }, - params: &[], + params: None, }; if new_attachments.is_empty() { @@ -2041,7 +2041,7 @@ impl Http { headers: None, method: LightMethod::Patch, route: Route::UserMe, - params: &[], + params: None, }) .await } @@ -2064,7 +2064,7 @@ impl Http { guild_id, role_id, }, - params: &[], + params: None, }) .await?; @@ -2098,7 +2098,7 @@ impl Http { route: Route::GuildRoles { guild_id, }, - params: &[], + params: None, }) .await?; @@ -2135,7 +2135,7 @@ impl Http { guild_id, event_id, }, - params: &[], + params: None, }) .await } @@ -2162,7 +2162,7 @@ impl Http { guild_id, sticker_id, }, - params: &[], + params: None, }) .await?; @@ -2188,7 +2188,7 @@ impl Http { route: Route::Channel { channel_id, }, - params: &[], + params: None, }) .await } @@ -2238,7 +2238,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await } @@ -2289,7 +2289,7 @@ impl Http { route: Route::GuildVoiceStateMe { guild_id, }, - params: &[], + params: None, }) .await } @@ -2340,7 +2340,7 @@ impl Http { route: Route::Webhook { webhook_id, }, - params: &[], + params: None, }) .await } @@ -2388,7 +2388,7 @@ impl Http { webhook_id, token, }, - params: &[], + params: None, }) .await } @@ -2468,7 +2468,7 @@ impl Http { webhook_id, token, }, - params: ¶ms, + params: Some(¶ms), }; if files.is_empty() { @@ -2498,11 +2498,6 @@ impl Http { token: &str, message_id: MessageId, ) -> Result { - let mut params = ArrayVec::<_, 1>::new(); - if let Some(thread_id) = thread_id { - params.push(("thread_id", thread_id.to_string())); - } - self.fire(Request { body: None, multipart: None, @@ -2513,7 +2508,10 @@ impl Http { token, message_id, }, - params: ¶ms, + params: thread_id + .map(|thread_id| [("thread_id", thread_id.to_string())]) + .as_ref() + .map(<[_; 1]>::as_slice), }) .await } @@ -2528,10 +2526,7 @@ impl Http { map: &impl serde::Serialize, new_attachments: Vec>, ) -> Result { - let mut params = ArrayVec::<_, 1>::new(); - if let Some(thread_id) = thread_id { - params.push(("thread_id", thread_id.to_string())); - } + let params = thread_id.map(|thread_id| [("thread_id", thread_id.to_string())]); let mut request = Request { body: None, @@ -2543,7 +2538,7 @@ impl Http { token, message_id, }, - params: ¶ms, + params: params.as_ref().map(<[_; 1]>::as_slice), }; if new_attachments.is_empty() { @@ -2567,11 +2562,6 @@ impl Http { token: &str, message_id: MessageId, ) -> Result<()> { - let mut params = ArrayVec::<_, 1>::new(); - if let Some(thread_id) = thread_id { - params.push(("thread_id", thread_id.to_string())); - } - self.wind(204, Request { body: None, multipart: None, @@ -2582,7 +2572,10 @@ impl Http { token, message_id, }, - params: ¶ms, + params: thread_id + .map(|thread_id| [("thread_id", thread_id.to_string())]) + .as_ref() + .map(<[_; 1]>::as_slice), }) .await } @@ -2604,7 +2597,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::StatusMaintenancesActive, - params: &[], + params: None, }) .await?; @@ -2648,7 +2641,7 @@ impl Http { route: Route::GuildBans { guild_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -2684,7 +2677,7 @@ impl Http { route: Route::GuildAuditLogs { guild_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -2701,7 +2694,7 @@ impl Http { route: Route::GuildAutomodRules { guild_id, }, - params: &[], + params: None, }) .await } @@ -2719,7 +2712,7 @@ impl Http { guild_id, rule_id, }, - params: &[], + params: None, }) .await } @@ -2743,7 +2736,7 @@ impl Http { route: Route::GuildAutomodRules { guild_id, }, - params: &[], + params: None, }) .await } @@ -2769,7 +2762,7 @@ impl Http { guild_id, rule_id, }, - params: &[], + params: None, }) .await } @@ -2792,7 +2785,7 @@ impl Http { guild_id, rule_id, }, - params: &[], + params: None, }) .await } @@ -2805,7 +2798,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::GatewayBot, - params: &[], + params: None, }) .await } @@ -2820,7 +2813,7 @@ impl Http { route: Route::ChannelInvites { channel_id, }, - params: &[], + params: None, }) .await } @@ -2838,7 +2831,7 @@ impl Http { route: Route::ChannelThreadMembers { channel_id, }, - params: &[], + params: None, }) .await } @@ -2853,7 +2846,7 @@ impl Http { route: Route::GuildThreadsActive { guild_id, }, - params: &[], + params: None, }) .await } @@ -2881,7 +2874,7 @@ impl Http { route: Route::ChannelArchivedPublicThreads { channel_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -2909,7 +2902,7 @@ impl Http { route: Route::ChannelArchivedPrivateThreads { channel_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -2937,7 +2930,7 @@ impl Http { route: Route::ChannelJoinedPrivateThreads { channel_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -2952,7 +2945,7 @@ impl Http { route: Route::ChannelThreadMemberMe { channel_id, }, - params: &[], + params: None, }) .await } @@ -2967,7 +2960,7 @@ impl Http { route: Route::ChannelThreadMemberMe { channel_id, }, - params: &[], + params: None, }) .await } @@ -2987,7 +2980,7 @@ impl Http { channel_id, user_id, }, - params: &[], + params: None, }) .await } @@ -3007,7 +3000,7 @@ impl Http { channel_id, user_id, }, - params: &[], + params: None, }) .await } @@ -3041,7 +3034,7 @@ impl Http { route: Route::ChannelWebhooks { channel_id, }, - params: &[], + params: None, }) .await } @@ -3056,7 +3049,7 @@ impl Http { route: Route::Channel { channel_id, }, - params: &[], + params: None, }) .await } @@ -3071,7 +3064,7 @@ impl Http { route: Route::GuildChannels { guild_id, }, - params: &[], + params: None, }) .await } @@ -3086,7 +3079,7 @@ impl Http { route: Route::StageInstance { channel_id, }, - params: &[], + params: None, }) .await } @@ -3101,7 +3094,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::Oauth2ApplicationCurrent, - params: &[], + params: None, }) .await } @@ -3114,7 +3107,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::UserMe, - params: &[], + params: None, }) .await } @@ -3129,7 +3122,7 @@ impl Http { route: Route::GuildEmojis { guild_id, }, - params: &[], + params: None, }) .await } @@ -3145,7 +3138,7 @@ impl Http { guild_id, emoji_id, }, - params: &[], + params: None, }) .await } @@ -3197,7 +3190,7 @@ impl Http { route: Route::Entitlements { application_id: self.try_application_id()?, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -3210,7 +3203,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::Gateway, - params: &[], + params: None, }) .await } @@ -3225,7 +3218,7 @@ impl Http { route: Route::Commands { application_id: self.try_application_id()?, }, - params: &[], + params: None, }) .await } @@ -3240,7 +3233,7 @@ impl Http { route: Route::Commands { application_id: self.try_application_id()?, }, - params: &[("with_localizations", String::from("true"))], + params: Some(&[("with_localizations", String::from("true"))]), }) .await } @@ -3256,7 +3249,7 @@ impl Http { application_id: self.try_application_id()?, command_id, }, - params: &[], + params: None, }) .await } @@ -3271,7 +3264,7 @@ impl Http { route: Route::Guild { guild_id, }, - params: &[], + params: None, }) .await } @@ -3286,7 +3279,7 @@ impl Http { route: Route::Guild { guild_id, }, - params: &[("with_counts", String::from("true"))], + params: Some(&[("with_counts", String::from("true"))]), }) .await } @@ -3302,7 +3295,7 @@ impl Http { application_id: self.try_application_id()?, guild_id, }, - params: &[], + params: None, }) .await } @@ -3322,7 +3315,7 @@ impl Http { application_id: self.try_application_id()?, guild_id, }, - params: &[("with_localizations", String::from("true"))], + params: Some(&[("with_localizations", String::from("true"))]), }) .await } @@ -3343,7 +3336,7 @@ impl Http { guild_id, command_id, }, - params: &[], + params: None, }) .await } @@ -3362,7 +3355,7 @@ impl Http { application_id: self.try_application_id()?, guild_id, }, - params: &[], + params: None, }) .await } @@ -3383,7 +3376,7 @@ impl Http { guild_id, command_id, }, - params: &[], + params: None, }) .await } @@ -3400,7 +3393,7 @@ impl Http { route: Route::GuildWidget { guild_id, }, - params: &[], + params: None, }) .await } @@ -3415,7 +3408,7 @@ impl Http { route: Route::GuildPreview { guild_id, }, - params: &[], + params: None, }) .await } @@ -3430,7 +3423,7 @@ impl Http { route: Route::GuildWelcomeScreen { guild_id, }, - params: &[], + params: None, }) .await } @@ -3445,7 +3438,7 @@ impl Http { route: Route::GuildIntegrations { guild_id, }, - params: &[], + params: None, }) .await } @@ -3460,7 +3453,7 @@ impl Http { route: Route::GuildInvites { guild_id, }, - params: &[], + params: None, }) .await } @@ -3480,7 +3473,7 @@ impl Http { route: Route::GuildVanityUrl { guild_id, }, - params: &[], + params: None, }) .await .map(|x: GuildVanityUrl| x.code) @@ -3515,7 +3508,7 @@ impl Http { route: Route::GuildMembers { guild_id, }, - params: ¶ms, + params: Some(¶ms), }) .await?; @@ -3540,7 +3533,7 @@ impl Http { route: Route::GuildPrune { guild_id, }, - params: &[("days", days.to_string())], + params: Some(&[("days", days.to_string())]), }) .await } @@ -3556,7 +3549,7 @@ impl Http { route: Route::GuildRegions { guild_id, }, - params: &[], + params: None, }) .await } @@ -3572,7 +3565,7 @@ impl Http { route: Route::GuildRoles { guild_id, }, - params: &[], + params: None, }) .await?; @@ -3607,7 +3600,7 @@ impl Http { guild_id, event_id, }, - params: &[("with_user_count", with_user_count.to_string())], + params: Some(&[("with_user_count", with_user_count.to_string())]), }) .await } @@ -3630,7 +3623,7 @@ impl Http { route: Route::GuildScheduledEvents { guild_id, }, - params: &[("with_user_count", with_user_count.to_string())], + params: Some(&[("with_user_count", with_user_count.to_string())]), }) .await } @@ -3682,7 +3675,7 @@ impl Http { guild_id, event_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -3698,7 +3691,7 @@ impl Http { route: Route::GuildStickers { guild_id, }, - params: &[], + params: None, }) .await?; @@ -3729,7 +3722,7 @@ impl Http { guild_id, sticker_id, }, - params: &[], + params: None, }) .await?; @@ -3769,7 +3762,7 @@ impl Http { route: Route::GuildWebhooks { guild_id, }, - params: &[], + params: None, }) .await } @@ -3822,7 +3815,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::UserMeGuilds, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -3866,7 +3859,7 @@ impl Http { route: Route::UserMeGuildMember { guild_id, }, - params: &[], + params: None, }) .await?; @@ -3913,7 +3906,7 @@ impl Http { route: Route::Invite { code, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -3930,7 +3923,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await?; @@ -3956,7 +3949,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -3988,7 +3981,7 @@ impl Http { route: Route::ChannelMessages { channel_id, }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -4006,7 +3999,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::StickerPacks, - params: &[], + params: None, }) .await .map(|s: StickerPacks| s.sticker_packs) @@ -4022,7 +4015,7 @@ impl Http { route: Route::ChannelPins { channel_id, }, - params: &[], + params: None, }) .await } @@ -4051,7 +4044,7 @@ impl Http { message_id, reaction: &reaction_type.as_data(), }, - params: ¶ms, + params: Some(¶ms), }) .await } @@ -4066,7 +4059,7 @@ impl Http { route: Route::Skus { application_id: self.try_application_id()?, }, - params: &[], + params: None, }) .await } @@ -4081,7 +4074,7 @@ impl Http { route: Route::Sticker { sticker_id, }, - params: &[], + params: None, }) .await } @@ -4103,7 +4096,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::StatusIncidentsUnresolved, - params: &[], + params: None, }) .await?; @@ -4127,7 +4120,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::StatusMaintenancesUpcoming, - params: &[], + params: None, }) .await?; @@ -4144,7 +4137,7 @@ impl Http { route: Route::User { user_id, }, - params: &[], + params: None, }) .await } @@ -4161,7 +4154,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::UserMeConnections, - params: &[], + params: None, }) .await } @@ -4174,7 +4167,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::UserMeDmChannels, - params: &[], + params: None, }) .await } @@ -4187,7 +4180,7 @@ impl Http { headers: None, method: LightMethod::Get, route: Route::VoiceRegions, - params: &[], + params: None, }) .await } @@ -4221,7 +4214,7 @@ impl Http { route: Route::Webhook { webhook_id, }, - params: &[], + params: None, }) .await } @@ -4261,7 +4254,7 @@ impl Http { webhook_id, token, }, - params: &[], + params: None, }) .await } @@ -4298,7 +4291,7 @@ impl Http { webhook_id, token, }, - params: &[], + params: None, }) .await } @@ -4319,7 +4312,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await } @@ -4334,7 +4327,7 @@ impl Http { route: Route::UserMeGuild { guild_id, }, - params: &[], + params: None, }) .await } @@ -4358,7 +4351,7 @@ impl Http { route: Route::ChannelMessages { channel_id, }, - params: &[], + params: None, }; if files.is_empty() { @@ -4390,7 +4383,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -4411,7 +4404,7 @@ impl Http { guild_id, user_id, }, - params: &[], + params: None, }) .await } @@ -4438,7 +4431,7 @@ impl Http { user_id, role_id, }, - params: &[], + params: None, }) .await } @@ -4460,10 +4453,10 @@ impl Http { route: Route::GuildMembersSearch { guild_id, }, - params: &[ + params: Some(&[ ("query", query.to_string()), ("limit", limit.unwrap_or(constants::MEMBER_FETCH_LIMIT).to_string()), - ], + ]), }) .await?; @@ -4493,7 +4486,7 @@ impl Http { route: Route::GuildPrune { guild_id, }, - params: &[("days", days.to_string())], + params: Some(&[("days", days.to_string())]), }) .await } @@ -4513,7 +4506,7 @@ impl Http { guild_id, integration_id, }, - params: &[], + params: None, }) .await } @@ -4574,7 +4567,7 @@ impl Http { channel_id, message_id, }, - params: &[], + params: None, }) .await } @@ -4604,7 +4597,7 @@ impl Http { /// let channel_id = ChannelId::new(381880193700069377); /// let route = Route::ChannelMessages { channel_id }; /// - /// let mut request = Request::new(route, LightMethod::Post, &[]).body(Some(bytes)); + /// let mut request = Request::new(route, LightMethod::Post).body(Some(bytes)); /// /// let message: Message = http.fire(request).await?; /// @@ -4644,7 +4637,7 @@ impl Http { /// let channel_id = ChannelId::new(381880193700069377); /// let route = Route::ChannelMessages { channel_id }; /// - /// let mut request = Request::new(route, LightMethod::Post, &[]).body(Some(bytes)); + /// let mut request = Request::new(route, LightMethod::Post).body(Some(bytes)); /// /// let response = http.request(request).await?; /// diff --git a/src/http/request.rs b/src/http/request.rs index f02aa03a01e..b5541670306 100644 --- a/src/http/request.rs +++ b/src/http/request.rs @@ -25,22 +25,18 @@ pub struct Request<'a> { pub(super) headers: Option, pub(super) method: LightMethod, pub(super) route: Route<'a>, - pub(super) params: &'a [(&'static str, String)], + pub(super) params: Option<&'a [(&'static str, String)]>, } impl<'a> Request<'a> { - pub fn new( - route: Route<'a>, - method: LightMethod, - params: &'a [(&'static str, String)], - ) -> Self { + pub fn new(route: Route<'a>, method: LightMethod) -> Self { Self { body: None, multipart: None, headers: None, method, route, - params, + params: None, } } @@ -60,7 +56,11 @@ impl<'a> Request<'a> { } pub fn params(mut self, params: &'a [(&'static str, String)]) -> Self { - self.params = params; + if params.is_empty() { + self.params = None; + } else { + self.params = Some(params); + } self } @@ -78,9 +78,9 @@ impl<'a> Request<'a> { path = path.replace("https://discord.com", proxy.trim_end_matches('/')); } - if !self.params.is_empty() { + if let Some(params) = self.params { path += "?"; - for (param, value) in self.params { + for (param, value) in params { write!(path, "&{param}={value}").unwrap(); } } @@ -138,11 +138,7 @@ impl<'a> Request<'a> { } #[must_use] - pub fn params_ref(&self) -> Option<&[(&'static str, String)]> { - if self.params.is_empty() { - None - } else { - Some(self.params) - } + pub fn params_ref(&self) -> Option<&'a [(&'static str, String)]> { + self.params } }