Skip to content

Commit

Permalink
Remove unneeded futures::iter::stream usage (serenity-rs#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored and mkrasnitski committed May 30, 2023
1 parent 8178bd5 commit 64d7c4b
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/model/guild/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ mod scheduled_event;
mod system_channel;
mod welcome_screen;

#[cfg(feature = "model")]
use futures::stream::StreamExt;
use serde::de::Error as DeError;
#[cfg(feature = "model")]
use tracing::error;
Expand Down Expand Up @@ -1775,7 +1773,8 @@ impl Guild {
/// **Note**: This will only search members that are cached. If you want to
/// search all members in the guild via the Http API, use
/// [`Self::search_members`].
pub async fn members_starting_with(
#[must_use]
pub fn members_starting_with(
&self,
prefix: &str,
case_sensitive: bool,
Expand All @@ -1786,8 +1785,10 @@ impl Guild {
|| !case_sensitive && starts_with_case_insensitive(name, prefix)
}

let mut members = futures::stream::iter(self.members.values())
.filter_map(|member| async move {
let mut members = self
.members
.values()
.filter_map(|member| {
let username = &member.user.name;

if starts_with(prefix, case_sensitive, username) {
Expand All @@ -1805,8 +1806,7 @@ impl Guild {
}
}
})
.collect::<Vec<(&Member, String)>>()
.await;
.collect::<Vec<(&Member, String)>>();

if sorted {
members.sort_by(|a, b| closest_to_origin(prefix, &a.1[..], &b.1[..]));
Expand Down Expand Up @@ -1847,7 +1847,8 @@ impl Guild {
/// **Note**: This will only search members that are cached. If you want to
/// search all members in the guild via the Http API, use
/// [`Self::search_members`].
pub async fn members_containing(
#[must_use]
pub fn members_containing(
&self,
substring: &str,
case_sensitive: bool,
Expand All @@ -1858,8 +1859,10 @@ impl Guild {
|| !case_sensitive && contains_case_insensitive(name, substring)
}

let mut members = futures::stream::iter(self.members.values())
.filter_map(|member| async move {
let mut members = self
.members
.values()
.filter_map(|member| {
let username = &member.user.name;

if contains(substring, case_sensitive, username) {
Expand All @@ -1877,8 +1880,7 @@ impl Guild {
}
}
})
.collect::<Vec<(&Member, String)>>()
.await;
.collect::<Vec<(&Member, String)>>();

if sorted {
members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..]));
Expand Down Expand Up @@ -1914,14 +1916,17 @@ impl Guild {
/// **Note**: This will only search members that are cached. If you want to
/// search all members in the guild via the Http API, use
/// [`Self::search_members`].
pub async fn members_username_containing(
#[must_use]
pub fn members_username_containing(
&self,
substring: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)> {
let mut members = futures::stream::iter(self.members.values())
.filter_map(|member| async move {
let mut members = self
.members
.values()
.filter_map(|member| {
let name = &member.user.name;

if (case_sensitive && name.contains(substring))
Expand All @@ -1932,8 +1937,7 @@ impl Guild {
None
}
})
.collect::<Vec<(&Member, String)>>()
.await;
.collect::<Vec<(&Member, String)>>();

if sorted {
members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..]));
Expand Down Expand Up @@ -1972,14 +1976,17 @@ impl Guild {
/// **Note**: This will only search members that are cached. If you want to
/// search all members in the guild via the Http API, use
/// [`Self::search_members`].
pub async fn members_nick_containing(
#[must_use]
pub fn members_nick_containing(
&self,
substring: &str,
case_sensitive: bool,
sorted: bool,
) -> Vec<(&Member, String)> {
let mut members = futures::stream::iter(self.members.values())
.filter_map(|member| async move {
let mut members = self
.members
.values()
.filter_map(|member| {
let nick = match member.nick {
Some(ref nick) => nick.to_string(),
None => member.user.name.to_string(),
Expand All @@ -1993,8 +2000,7 @@ impl Guild {
None
}
})
.collect::<Vec<(&Member, String)>>()
.await;
.collect::<Vec<(&Member, String)>>();

if sorted {
members.sort_by(|a, b| closest_to_origin(substring, &a.1[..], &b.1[..]));
Expand Down

0 comments on commit 64d7c4b

Please sign in to comment.