From 59c24502f8b2c8381ffdefab7b5f105cf67c9c63 Mon Sep 17 00:00:00 2001 From: Gnome! Date: Mon, 28 Oct 2024 22:36:01 +0000 Subject: [PATCH] Backport: Fix model functions using `SerializeIter` (#3006) This is a backport of #2955 to `current`. `bulk_ban` is currently uncallable so this "breaking" change doesn't actually break anyone. --- src/model/guild/guild_id.rs | 9 ++++----- src/model/guild/mod.rs | 4 ++-- src/model/utils.rs | 23 ----------------------- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/src/model/guild/guild_id.rs b/src/model/guild/guild_id.rs index cad6731b377..165e9e90249 100644 --- a/src/model/guild/guild_id.rs +++ b/src/model/guild/guild_id.rs @@ -33,7 +33,6 @@ use crate::http::{CacheHttp, Http, UserPagination}; use crate::internal::prelude::*; #[cfg(feature = "model")] use crate::json::json; -use crate::model::guild::SerializeIter; use crate::model::prelude::*; #[cfg(feature = "model")] @@ -263,18 +262,18 @@ impl GuildId { pub async fn bulk_ban( self, http: &Http, - users: impl IntoIterator, + user_ids: &[UserId], delete_message_seconds: u32, reason: Option<&str>, ) -> Result { #[derive(serde::Serialize)] - struct BulkBan { - user_ids: I, + struct BulkBan<'a> { + user_ids: &'a [UserId], delete_message_seconds: u32, } let map = BulkBan { - user_ids: SerializeIter::new(users.into_iter()), + user_ids, delete_message_seconds, }; diff --git a/src/model/guild/mod.rs b/src/model/guild/mod.rs index c6836bc1e71..12654ec20e0 100644 --- a/src/model/guild/mod.rs +++ b/src/model/guild/mod.rs @@ -534,7 +534,7 @@ impl Guild { pub async fn bulk_ban( &self, cache_http: impl CacheHttp, - users: impl IntoIterator, + user_ids: &[UserId], delete_message_seconds: u32, reason: Option<&str>, ) -> Result { @@ -545,7 +545,7 @@ impl Guild { } } - self.id.bulk_ban(cache_http.http(), users, delete_message_seconds, reason).await + self.id.bulk_ban(cache_http.http(), user_ids, delete_message_seconds, reason).await } /// Returns the formatted URL of the guild's banner image, if one exists. diff --git a/src/model/utils.rs b/src/model/utils.rs index e931734b7a0..b1a1cb535ad 100644 --- a/src/model/utils.rs +++ b/src/model/utils.rs @@ -1,4 +1,3 @@ -use std::cell::Cell; use std::fmt; use std::hash::Hash; use std::marker::PhantomData; @@ -85,28 +84,6 @@ where } } -pub(super) struct SerializeIter(Cell>); - -impl SerializeIter { - pub fn new(iter: I) -> Self { - Self(Cell::new(Some(iter))) - } -} - -impl serde::Serialize for SerializeIter -where - Iter: Iterator, - Item: serde::Serialize, -{ - fn serialize(&self, serializer: S) -> Result { - let Some(iter) = self.0.take() else { - return serializer.serialize_seq(Some(0))?.end(); - }; - - serializer.collect_seq(iter) - } -} - pub(super) enum StrOrInt<'de> { String(String), Str(&'de str),