Skip to content

Commit 59c2450

Browse files
authored
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.
1 parent 2fb922e commit 59c2450

File tree

3 files changed

+6
-30
lines changed

3 files changed

+6
-30
lines changed

src/model/guild/guild_id.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use crate::http::{CacheHttp, Http, UserPagination};
3333
use crate::internal::prelude::*;
3434
#[cfg(feature = "model")]
3535
use crate::json::json;
36-
use crate::model::guild::SerializeIter;
3736
use crate::model::prelude::*;
3837

3938
#[cfg(feature = "model")]
@@ -263,18 +262,18 @@ impl GuildId {
263262
pub async fn bulk_ban(
264263
self,
265264
http: &Http,
266-
users: impl IntoIterator<Item = UserId>,
265+
user_ids: &[UserId],
267266
delete_message_seconds: u32,
268267
reason: Option<&str>,
269268
) -> Result<BulkBanResponse> {
270269
#[derive(serde::Serialize)]
271-
struct BulkBan<I> {
272-
user_ids: I,
270+
struct BulkBan<'a> {
271+
user_ids: &'a [UserId],
273272
delete_message_seconds: u32,
274273
}
275274

276275
let map = BulkBan {
277-
user_ids: SerializeIter::new(users.into_iter()),
276+
user_ids,
278277
delete_message_seconds,
279278
};
280279

src/model/guild/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl Guild {
534534
pub async fn bulk_ban(
535535
&self,
536536
cache_http: impl CacheHttp,
537-
users: impl IntoIterator<Item = UserId>,
537+
user_ids: &[UserId],
538538
delete_message_seconds: u32,
539539
reason: Option<&str>,
540540
) -> Result<BulkBanResponse> {
@@ -545,7 +545,7 @@ impl Guild {
545545
}
546546
}
547547

548-
self.id.bulk_ban(cache_http.http(), users, delete_message_seconds, reason).await
548+
self.id.bulk_ban(cache_http.http(), user_ids, delete_message_seconds, reason).await
549549
}
550550

551551
/// Returns the formatted URL of the guild's banner image, if one exists.

src/model/utils.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::cell::Cell;
21
use std::fmt;
32
use std::hash::Hash;
43
use std::marker::PhantomData;
@@ -85,28 +84,6 @@ where
8584
}
8685
}
8786

88-
pub(super) struct SerializeIter<I>(Cell<Option<I>>);
89-
90-
impl<I> SerializeIter<I> {
91-
pub fn new(iter: I) -> Self {
92-
Self(Cell::new(Some(iter)))
93-
}
94-
}
95-
96-
impl<Iter, Item> serde::Serialize for SerializeIter<Iter>
97-
where
98-
Iter: Iterator<Item = Item>,
99-
Item: serde::Serialize,
100-
{
101-
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
102-
let Some(iter) = self.0.take() else {
103-
return serializer.serialize_seq(Some(0))?.end();
104-
};
105-
106-
serializer.collect_seq(iter)
107-
}
108-
}
109-
11087
pub(super) enum StrOrInt<'de> {
11188
String(String),
11289
Str(&'de str),

0 commit comments

Comments
 (0)